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!