
Error in using syms
14 views (last 30 days)
Show older comments
Mohammed Tohifah
on 18 Apr 2021
Answered: Star Strider
on 18 Apr 2021
So I have this code
syms x t s X F
F=laplace('diff(x(t),t,t)+5*diff(x(t),t)+610*x(t)-exp(-t)',s);
F=subs(F,{'laplace(x(t),t,s)'},{X});
F=subs(F,{'x(0)','Dx(0)'},{0,0});
x=solve(F,'X');
x=ilaplace(x);
I'm using Matlab 2020a. It gives me this error:
Character vectors and strings in the first argument can only specify a variable or number. To evaluate character vectors and strings representing symbolic expressions, use 'str2sym'.
S = convertChar(x);
S.s = tomupad(x);
if ~isa(f, 'sym'), f = sym(f); end
L = transform('symobj::laplace', 't', 's', 'z', F, varargin{:});
What should I change in this so that I get the required output?
0 Comments
Accepted Answer
Star Strider
on 18 Apr 2021
Remove the single quotes, define ‘x’ as ‘x(t)’, and define ‘Dx’ (and ‘D2x’ if you want to), explicity:
syms x(t) t s X F
Dx = diff(x);
D2x = diff(Dx);
F=laplace(D2x+5*Dx+610*x(t)-exp(-t),s);
F=subs(F,{laplace(x(t),t,s)},{X});
F=subs(F,{x(0),Dx(0)},{0,0});
x=solve(F,X);
x=ilaplace(x)
producing in LaTeX format —

The code is otherwise unchanged.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!