Ode45 and Cauchy problem
古いコメントを表示
Hi everyone, I'm a new Matlab user. I need to resolve this Cauchy problem: y'' = -y^2 with y(0) = pi and y'(0) = log2, in the point t = 1 with ODE45. So i write this script:
CI = [pi log(2)]; tspan = [0 1]; [t1, y1] = ode45(@myode, tspan, CI); y1(end);
and the function @myode also is
function dydt = myode(t,y) dydt = [y(2); -y(2)-y(1).^2]; end
The correct solution would be 0.1596, while my solution is -2.8273 Why? Where I failed? Thanks for the help!
回答 (1 件)
Star Strider
2018 年 5 月 6 日
Two small problems — your derivation of the differential equation is incorrect (I used the Symbolic Math Toolbox to derive it), and you need to return the last entry of the first column of ‘t1’:
syms y(t)
Eqn = diff(y,2) == -y^2;
[VF,Sb] = odeToVectorField(Eqn)
myode = @(t,y) [y(2); -y(1).^2];
CI = [pi log(2)];
tspan = [0 1];
[t1, y1] = ode45(myode, tspan, CI);
Solution = y1(end,1)
figure(1)
plot(t1, y1)
grid
Solution =
0.159604012575497
カテゴリ
ヘルプ センター および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!