Problem with Ode Solver

1 view (last 30 days)
Bodhisattva
Bodhisattva on 20 Feb 2015
Answered: Torsten on 20 Feb 2015
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?

Answers (1)

Torsten
Torsten on 20 Feb 2015
1. The vector of Initial values is [12 21].
2. The plot command must read
plot (t,x(:,1));
Best wishes
Torsten.

Tags

Community Treasure Hunt

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

Start Hunting!