I have a problem with ode solvers for 3 ode.

I write my 3 ode's and I want to plot a maximum point for each value of "a", I've done a similar problem and it worked, but in this one I have the following errors:
Warning: Failure at t=2.599899e+00.
Unable to meet integration tolerances without reducing the step size below the smallest value allowed (7.105427e-15) at time t.
> In ode45 (line 308)
In Untitled (line 9)
Index exceeds matrix dimensions.
Error in Untitled (line 12)
if ( (x(n,1) > x(n-1,1)) && (x(n,1) > x(n+1,1)) )
(I have the same error for ode15s)
I don't know what's wrong, here is the following code with the equations:
clear all
t0=0;
a=[0];
k=1;
i=1;
for a=-2:0.1:2
f = @(t,x) [x(2);x(3);-x(2)+3*x(2)*x(2)-x(1)*x(1)-x(1)*x(3)-a];
[t,x] = ode45(f,[t0:0.01:300],[0.51 0.51 0.51]);
for n=25000:1:30000
if ( (x(n,1) > x(n-1,1)) && (x(n,1) > x(n+1,1)) )
plot (x(n,1), a, '.')
hold on
n=n+1;
end
end
end

Answers (1)

Torsten
Torsten on 12 Jun 2017
Edited: Torsten on 12 Jun 2017
ode45 has problems to integrate your system of ODEs for a certain a-value.
That's why x has dimension smaller than 30001, and you get the "Index exceeds matrix dimensions" error.
Best wishes
Torsten.

Community Treasure Hunt

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

Start Hunting!