Effacer les filtres
Effacer les filtres

Second order ODE with dsolve

3 vues (au cours des 30 derniers jours)
Jacob Yarinsky
Jacob Yarinsky le 25 Jan 2020
Commenté : Jacob Yarinsky le 25 Jan 2020
Hello All,
Trying to solve this ODE.
clear,clc
syms y(t) x2(t) x1(t) a b
dy=diff(y,t);
ode = diff(y,t,2) == a.*d) + b.*y - diff(x2,t)./10 + x1;
cond1 = y(0)==0;
cond2 = dy(0)==0;
conds=[cond1 cond2];
sol1=dsolve(ode,conds)
t=(0:.1:20);
x2(t)=20.*heaviside(t);
x1(t)=0;
out=eval(sol1);
plot(t,out)
%%%% Getting this error %%%%
Error using eval
Must be a string scalar or character vector.
Error in Homework_1 (line 14)
out=eval(sol1);

Réponse acceptée

Walter Roberson
Walter Roberson le 25 Jan 2020
ode = diff(y,t,2) == a.*d) + b.*y - diff(x2,t)./10 + x1;
You are missing a ( . Also, dy is not defined. Perhaps d) is intended to be dy ?
You have two differential functions, y and x2, but you are only sending one equation to dsolve() . You need at least one equation for each function .
Or... you could define x2 before you define ode, so that ode becomes an equation with only one differential variable.
out=eval(sol1);
eval() is not defined for symbolic expressions. It does something in new enough releases, but the something it does is almost never what you would like to have happen. Use subs() instead.
  1 commentaire
Jacob Yarinsky
Jacob Yarinsky le 25 Jan 2020
Thank you for this. I tried to remove my additional comments for clarity and mistakenly erased the y from dy. Defining x2 and x1 before creating ode worked perfectly.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by