eqn = sym() not working

조회 수: 3 (최근 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 CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by