Second order ODE with dsolve

7 次查看(过去 30 天)
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);

采纳的回答

Walter Roberson
Walter Roberson 2020-1-25
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 个评论
Jacob Yarinsky
Jacob Yarinsky 2020-1-25
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by