Second order ODE with dsolve

1 回表示 (過去 30 日間)
Jacob Yarinsky
Jacob Yarinsky 2020 年 1 月 25 日
コメント済み: Jacob Yarinsky 2020 年 1 月 25 日
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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by