use MATLAB(R) to solve a previously defined system, f, with ODE45 - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Mathematics : Numerical Computations : Matlab : Matlab/ode45

Matlab[ode45] - use MATLAB(R) to solve a previously defined system, f, with ODE45

Matlab[ode15s] - use MATLAB(R) to solve a previously defined system, f, with ODE15s

Calling Sequence

ode45(f, Trange, IC)

ode45(f, Trange, IC, tol=Tol)

ode15s(f, Trange, IC)

ode15s(f, Trange, IC, tol=Tol)

Parameters

f

-

string naming a function defined in MATLAB®

Trange

-

range, t_initial..t_final

IC

-

initial conditions vector; for example, [0, 0, 0]

tol=Tol

-

optional floating-point setting for tolerance (default is .001)

Description

• 

The ode45 command uses MATLAB® to compute the ODE45 solution of a differential system. The ode15s command uses MATLAB® to compute the ODE15S solution of a differential system.

• 

To be valid, the call must name the function (f) defined in MATLAB®, and specify both the time range (Trange) and the initial condition vector (IC).

• 

The function f must either be a built-in MATLAB® function, or a function defined in the file f.m in the active MATLAB® path

• 

The time range must contain both a start time (t_initial) and an end time (t_final).

• 

The initial condition (IC) must have a dimension consistent with the dimension of the system defined in the function, f.

• 

The tolerance option (specified using 'tol'=Tol) must be a floating-point value.  It defaults to .001 if not specified.

• 

Executing the ode45 command returns two Vectors: (T, X). T is the Vector of time steps where f was evaluated, and X is a Vector of values of f, evaluated at times in T.

Examples

withMatlab:

Call ode45 to work on a built-in MATLAB® function.

T,Y:=ode45vdp1,0..20,2,0

Call ode15s to work on a built-in MATLAB® function.

T,Y:=ode15svdp1000,0..30,2,0

Create a user-defined function, rocket, in Maple.  The file may also be predefined in the current path.

file:=openC:MATLABwork ocket.m,WRITE:

filecontents:= function yp = rocket(t,y) % time the rocket catches the target global INTERCEPT; % minimum distance representing intercept global DMIN; % ratio of pursuer speed to target speed k=1.3; % find speed and position of target % (other equations can be substituted here) if t < 10 % target changes direction after 10 seconds p = [ 10; t; 0 ]; vt = [ 0 ; 1; 0 ]; else p = [ 10; 10; t-10 ]; vt = [ 0 ; 0; 1 ]; end d = sqrt(sum((p-y).^2)); % calculate distance between P and T if d < DMIN % check if pursuer has caught targetN if t < INTERCEPT % if this is the first time, set the INTERCEPT = t; % interception time end k = 1; % slow down the pursuer end vp = k*sqrt(sum(vt.^2)); % set speed of pursuer yp = vp*(p-y)/d; % determine new position of pursuer &colon;

writelinefile&comma;filecontents&colon;

closefile&colon;

Use the ssystem command to set the permissions on UNIX systems.

ssystemchmod a+r rocket.m&colon;

Open the "Matlab Link".

withMatlab

Before accessing the user-defined function, the file needs to be opened (in MATLAB®).

evalMopen('C:MATLABwork ocket.m')&colon;

Set global variables (in MATLAB®).

setvarDMIN&comma;0.5&comma;&apos;globalvar&apos;

setvarINTERCEPT&comma;&infin;&comma;&apos;globalvar&apos;

Setup the problem.

ti:=0&colon;

tf:=20&colon;

Yo:=0&comma;0&comma;0&colon;

Solve the problem.

T&comma;Y:=ode45rocket&comma;ti..tf&comma;Yo&comma;&apos;tol&apos;&equals;0.0005&colon;

Plot the results.

pursuer_plot:=plots&lsqb;pointplot3d&rsqb;convertY&comma;listlist&comma;color&equals;blue&comma;symbol&equals;diamond&colon;

target_plot:=plots&lsqb;pointplot3d&rsqb;seq10&comma;t&comma;0&comma;t&equals;ti..10&comma;seq10&comma;10&comma;t10&comma;t&equals;10..tf&comma;color&equals;red&comma;symbol&equals;cross&colon;

plots&lsqb;display&rsqb;pursuer_plot&comma;target_plot&comma;axes&equals;normal

See Also

dsolve, Matlab, Matlab[evalM], MatlabMatrix


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam