フィルターのクリア

ODE45 and dsolve result difference

24 ビュー (過去 30 日間)
Muhammad Asad
Muhammad Asad 2024 年 7 月 4 日 11:57
編集済み: Walter Roberson 2024 年 7 月 4 日 17:34
Hi, i am struggling to get similar answer using ODE45 and dsolve. I dont know whats wrong? if any one can help, please.
-----------code using dsolve-------------------
syms x y(x)
Dy = diff(y);
Eq= diff(y,x,2)==2-2*Dy-8*x;
cond1 = y(0) == 1;
cond2 = Dy(0) == -2;
conds = [cond1 cond2];
Sol = dsolve(Eq,conds)
Sol = 
fplot(Sol,[0 2])
-----------code using ODE45-------------------
[x,y]=ode45(@twofirstorder,[0 2],[1 -2]);
plot(x,y)
function dydx = twofirstorder(x,y)
dydx(1)=y(2);
dydx(2)=2-2*y(2)-8*y(1);
dydx=dydx';
end

採用された回答

Torsten
Torsten 2024 年 7 月 4 日 12:02
dydx(2)=2-2*y(2)-8*x;
instead of
dydx(2)=2-2*y(2)-8*y(1);
  1 件のコメント
Muhammad Asad
Muhammad Asad 2024 年 7 月 4 日 12:06
amazing, thanks

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by