MATLAB Answers

how to uses str2sym

32 views (last 30 days)
Rim SALAH
Rim SALAH on 10 Nov 2020
Answered: Pranav Verma on 13 Nov 2020
clear all;clc
disp('------');
disp('The Nonlinear systems should be written in thefollowing form');
disp('Sliding Mode Controller for a class of Nonlinear systems');
disp(' State space equations x=f(x)+gu ');
disp('-----------');
n=input('Number of states:=');
nin=input('Number of inputs:=');
x=sym(zeros(1,n));
u=sym(zeros(1,nin));
par=input('Parameters ','s');
eval(sprintf('syms %s',par));
parameters=sprintf('%s',par);
for j=1:n
eval(sprintf('syms x%d',j))
x(:,j)=sprintf('x%d',j);
end
for k=1:nin
eval(sprintf('syms u%d',k));
u(:,k)=sprintf('u%d',k);
end
syms u
f=input('The vector f(x):=','s');
g=input('The vector g(x):=','s');
Hc=input('The output variables:=','s');
[Lhf,Lhg,dh,L,u,r]=NonContSidFed(f,g,Hc,x,u);
[Surf,dSurf,dd,K,Uc]=SlidingModeTerms(Hc,L,r,Lhg);

  0 Comments

Sign in to comment.

Answers (1)

Pranav Verma
Pranav Verma on 13 Nov 2020
Hi Rim,
The str2sym function takes in a symbolic expression in a string form as input & evaluates it. Please refer to the below example illustrating the same:
>> st = '2+2';
>> str2sym(st)
ans =
4
Thanks

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by