MATLAB, Differential Equations help

Click For Summary
SUMMARY

The discussion centers on resolving an issue with MATLAB's ODE solver, specifically using the function ode45 for a system of ordinary differential equations (ODEs). The user encountered an error indicating a mismatch between the length of the output vector from the function hode and the initial conditions vector. The function hode is defined to return a vector of length 2, while the initial conditions provided consist of four elements. The solution involves ensuring that the number of equations matches the number of initial conditions.

PREREQUISITES
  • Understanding of MATLAB syntax and function definitions
  • Familiarity with ordinary differential equations (ODEs)
  • Knowledge of MATLAB's ode45 function for numerical solutions
  • Ability to interpret error messages in MATLAB
NEXT STEPS
  • Review MATLAB documentation on ode45 and its requirements
  • Learn how to formulate systems of first-order ODEs from higher-order equations
  • Explore example files within MATLAB that demonstrate ODE solving
  • Practice debugging MATLAB code by analyzing error messages
USEFUL FOR

Students and professionals new to MATLAB, particularly those working with differential equations and numerical methods for solving ODEs.

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
No luck? :(
 
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
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
11K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K