MATLAB, Differential Equations help

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 3K views
btbam91
Messages
91
Reaction score
0
[PLAIN]http://img19.imageshack.us/img19/9946/matlabhelp.png

Alright guys, I am extremely new with MATLAB, and this ODE problem is giving me a hard time.

For my function file, I got


function dy = hode(t,y)
dy = [y(4);
-(3/5)*y(4)-(138/100)*y(3)-(231/500)*y(2)-(2929/10000)*y(1)];
end


And for my mainprogram-odesolver-plot file I got


tspan=[0,100];
init=[2,1,0,0];
[t,y] = ode45(@hode,tspan,init);
plot(t,y,'r')
\


Unfortunately, I keep getting these errors.


? Error using ==> odearguments at 116
HODE returns a vector of length 2, but the length of initial conditions
vector is 4. The vector returned by HODE and the initial conditions
vector must have the same number of elements.

Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn,
...

Error in ==> mainprogram at 3
[t,y] = ode45(@hode,tspan,init);



This template was given to help us out.

[PLAIN]http://img808.imageshack.us/img808/5205/matlabhelp2.png


Thanks for the help!
 
Last edited by a moderator:
Physics news on Phys.org
I would suggest you write out the system of first order ODEs first. There should be example files within MATLAB itself that should help you. What are these equations?

Mat