HyperMath

ODE11

ODE11

Previous topic Next topic No expanding text in this topic  

ODE11

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

Solves a set of first-order, ordinary differential equations using the Adams-Moulton method of integration.  At each time step, it solves the nonlinear system by functional iteration.

Syntax

x = ODE11(func, init, time, reltol, abstol, userdata)

x = ODE11(func, init, start, end, points, reltol, abstol, userdata)

Arguments

Name

Description

 

func

The name of the function that describes the systems of equations.  Must be a string.  The function must return the derivative of each state.  See the Comments section.

 

init

A vector of the initial conditions for the state variables of the system.  Its length must equal the number of equations in the system.  The order of the variables will be followed in the system function.  See the Comments section.

 

time

A vector of time stamps where the solutions are to be returned.  Must be positive monotonic.

 

start

A non-negative scalar specifying the start time of the solution.

 

end

A non-negative scalar specifying the end time of the solution. Must be greater than start.

 

points

A positive scalar specifying the number of points between start and end where the solutions are to be returned.

 

reltol

(optional)

Relative tolerance of convergence.  This applies to all states. Must be a positive scalar.  Defaults to 1.0e-3.

 

abstol

(optional)

Absolute tolerances below which the solutions are unimportant.  This is used when a solution approaches zero.  If it is a vector with the same length as init, then each state has its own tolerance. If it is a one element vector, then the value applies to each state. If it is an empty vector or omitted, the default is 1.0e-6 for each state. Every tolerance value must be positive.

 

userdata (optional)

Data matrix that is passed to the user defined function at each iteration. This can be used to supply data that are defined outside the function. It can be omitted or empty.

Output

Name

Description

 

x

A matrix of the solutions at each time stamp.  Each column represents a state variable of the system.

Example

Solve the van der Pol equation for a time span of 0 to 10 seconds with increments of 0.1 second.

 

Syntax

// First define the van der Pol system in a function

function vdp(t, y, d)

{

 // t is a scalar, the independent variable

 // y is a 2 element vector, one for each state

// d is the user data (not used)

 mu = 1;

 // Equation for first state

dy1dt = y(2);

 // Equation for second state

 dy2dt = mu*(1.0 - y(1)^2) * y(2) - y(1);        

     yp = [dy1dt; dy2dt];

 

 return yp; // return the derivatives of the states

}

init = [2, 0]; // initial conditions of the 2 states

t = [0:0.1:10]; // time span

x = ODE11("vdp", init, t, 0.001, [0.001,0.001]);

PlotLine(t, x(:,1));

PlotLine(t, x(:,2));

 

Result

 

x will be a 101x2 matrix, with the first column representing the dependant variable and the second column its derivative in this case.

Comments

ODE11 is not suitable for stiff problems.

The initial condition vector can be either a row or a column. Inside the user function, the state variable vector will be a column.

If an optional argument is supplied, all other optional arguments up until that one must be supplied also.

The user function must accept at least two inputs. The first one is the time-step and the second one is a column vector of the state variable values at that step.  Optionally, it can accept a third argument which is a matrix that can be used to pass in any additional user data.

See Also:

RK45

ODE21

ODE22a

HMath-4010: Solving Ordinary Differential and Differential Algebraic Equations