eqn = sym() not working

2 ビュー (過去 30 日間)
Aric Rozario
Aric Rozario 2021 年 4 月 16 日
回答済み: Shashank Gupta 2021 年 4 月 19 日
%first define the variables
title 'graph of the forcing function';
ezplot( heaviside(t-pi) + (-1)*heaviside(t-10), [0 15]);%graphing the forcing function
ylabel y; xlabel t;
syms s t Y %first define the variables
eqn = sym(('D(D(y))(t) + 3*D(y)(t) + 2*y(t) = heaviside(t-pi) + (-1)*heaviside(t-10)'));
%defining the differential equation
lteqn = laplace(eqn , t, s);%find the laplace transform
neweqn = subs(lteqn , {'laplace(y(t),t,s)' , 'y(0)', 'D(y)(0)'} , {Y,1,0});%put initial conditions into laplace transform
ytrans = solve(neweqn, Y);%solving the Laplace transform for Y
y = ilaplace(ytrans , s, t)%finding the inverse laplace transform
ezplot( y , [0 15]);%plot the laplace solution on interval 0<t<15
title 'graph of Laplace Transform Solution for y" + 2y` +2y = h(t)';
ylabel y; xlabel t;
the output is as follows:
Error using sym>convertChar (line 1557)
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'.
Error in sym>tomupad (line 1273)
S = convertChar(x);
Error in sym (line 229)
S.s = tomupad(x);
Error in Problem_Set_E (line 105)
eqn = sym(('D(D(y))(t) + 3*D(y)(t) + 2*y(t)
= heaviside(t-pi) + (-1)*heaviside(t-10)'));

回答 (1 件)

Shashank Gupta
Shashank Gupta 2021 年 4 月 19 日
Hi Aric,
As the error message says, the function "sym" does not support a character array or a string, if you want to convert such datatypes to symbolic variable, all you need to do is use str2sym function as suggested in the error message.
I hope this helps.
Cheers

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by