Error in using syms

조회 수: 23 (최근 30일)
Mohammed Tohifah
Mohammed Tohifah 2021년 4월 18일
답변: Star Strider 2021년 4월 18일
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?

채택된 답변

Star Strider
Star Strider 2021년 4월 18일
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개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by