From: J on
I am trying to do Euler's method to integrate the Rossler equations:

M-file:

function ydot = rossler(a,y)
ydot(1) = -y(2)-y(3); %(1a)
ydot(2) = y(1) + a*y(2); %(1b)
ydot(3) = 0.6 + y(3)*(y(1)-6) %(1c)


>> a = -1;
>> h = 0.01;
>> t = [0:h:100]; %This is the time discretisation.
>> y(1)=5; y(2)=0; y(3)=0; %These are the initial conditions.
>> for n=1:10000 %This is the Euler Step.
y(n+1,:) = y(n,:) + h*rossler(a,y(n,:));
end

??? Attempted to access y(3); index out of bounds because
numel(y)=2.

Error in ==> rossler at 2
ydot(1) = -y(2)-y(3); %(1a)



I don't understand "numel(y)=2" and I also fail to see the error in rossler at 2.

Any suggestions please.
Thank you.
From: Walter Roberson on
J wrote:

>>> y(1)=5; y(2)=0; y(3)=0; %These are the initial conditions.

This creates a column vector

>>> for n=1:10000 %This is the Euler Step.
> y(n+1,:) = y(n,:) + h*rossler(a,y(n,:));

And this passes in all the rows of one column. Since there is only one
row per column, it is going to pass in a single value.

> end

I would suggest that perhaps the argument you want to pass is not y(n,:)
but rather y(n:n+2) ... except that's probably not right for the formula
either. Are you sure you want to change y(2) after you have already used
y(2) in a calculation ??