Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations JAE on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

MatLab: calling ode45 with parameter passing in

Status
Not open for further replies.

Matthew2005

Specifier/Regulator
Joined
Jul 31, 2005
Messages
1
Location
US
% How do I call sumX in ode45 where I can pass in 'ab' paramter? x & y are part of the ODE problems
% tspan=[0 20] initial value: [0 1] options []
[T Y]=ode45(@sumX,[0 10],[0 1],[]);




% sumX.m
function dy=sumX(ab,x,y)

dy1=y(2);
dy2=-y(1)+ab*(y(1)^2);

dy=[dy1; dy2];


%%%%%%%%%%%%%%%
Thanks
 
Try this:

function dy = sumX(x,y,ab)

dy1 = y(2);
dy2 = -y(1) + ab*(y(1)^2);

dy = [dy1;dy2];

then call using ode45

[T,Y] = ode45(@sumX,[tspan],[initial],[options],ab);

after the options space you can pass any parameters you want into ode45. This helps if you must change parameters often, and don't like editing the script file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top