Error in using syms

14 views (last 30 days)
Mohammed Tohifah
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);
Error in sym (line 229)
S.s = tomupad(x);
Error in transform (line 22)
if ~isa(f, 'sym'), f = sym(f); end
Error in sym/laplace (line 28)
L = transform('symobj::laplace', 't', 's', 'z', F, varargin{:});
What should I change in this so that I get the required output?

Accepted Answer

Star Strider
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.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!