Reputation: 7592
Apparently this might be a banal error, but I cannot figure out how to do it correctly (my first day with octave). I want to define the second order ODE d²x/dt² + M/L * dx/dt + 5x = 0 as system of ODEs. ODE2.m
looks like this:
function dz = ODE2(z,t)
%% d^2x/dt^2 + M/L * dx/dt + 5x = 0
M = 2;
L = 10;
dz = zeros(2,1);
dz(1) = z(2); % <--- apparently here's something wrong?!
dz(2) = -(M/L)*z(2)-5*z(1);
end
Then I do
t = linspace(0,1,100);
z = lsode(ODE2,[1;1],t);
...
But I get
error: 'z' undefined near line 6 column 11
However, I thought z
is defined as argument in the first line of ODE2.m
. Maybe the problem is that z
is a vector and this is unknown at definition time, but how to do it properly than? How to define the equation and solve it with lsode
?
Upvotes: 4
Views: 2639
Reputation: 74940
In the call z=lsode(ODE2,[1;1],t);
, ODE2
is interpreted as a function call, which will evaluate the function and then run into the issue that there are no input arguments. Note you will get the same error if you split the statement into fun=ODE2; z=lsode(fun,[1;1],t);
Assuming that Octave works the save way as Matlab, you need to pass the reference to ODE2
as a function handle, z=lsode(@ODE2,[1;1],t);
will work.
Upvotes: 5