eqn = sym() not working

5 vues (au cours des 30 derniers jours)
Aric Rozario
Aric Rozario le 16 Avr 2021
%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)'));

Réponses (1)

Shashank Gupta
Shashank Gupta le 19 Avr 2021
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

Community Treasure Hunt

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

Start Hunting!

Translated by