Problem with Ode Solver
显示 更早的评论
The differential equation is y''+ 5y'+7y=0, with y(0)=12 and y'(0)=21. Accordingly, I created a matlab function
function dxdt=odeprac(t,x)
dxdt =[x(2); -7*x(1)-5*x(2)];
Here, y=x(1) and y'=x(2) If I run the command
[t,x] = ode45(@odeprac,tspan,[21; 12]);
>> plot(t,x(1));
Then I do not get the time path of y (which, ideally, should show waves), but a horizontal line at x1=21. Even rescaling the axes or trying other ode solver do not help.
What other options I may try?
回答(1 个)
Torsten
2015-2-20
1. The vector of Initial values is [12 21].
2. The plot command must read
plot (t,x(:,1));
Best wishes
Torsten.
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!