# eqn = sym() not working

4 Ansichten (letzte 30 Tage)
Aric Rozario am 16 Apr. 2021
Beantwortet: Shashank Gupta am 19 Apr. 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'.
S = convertChar(x);
Error in sym (line 229)
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)'));
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Shashank Gupta am 19 Apr. 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
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Symbolic Variables, Expressions, Functions, and Preferences finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!