Thank you for visiting our site! You landed on this page because you entered a search term similar to this: Matlab solve second order differential equations, here's the result:
ode23, ode45
Purpose
Solve ordinary differential equations.Synopsis
[t,x] = ode23('xprime',t0,tf,x0)[t,x] = ode23('xprime',t0,tf,x0,tol,trace)[t,x] = ode45('xprime',t0,tf,x0)[t,x] = ode45('xprime',t0,tf,x0,tol,trace)
Description
ode23 and ode45 are functions for the numerical solution of ordinary differential equations. They can solve simple differential equations or simulate complex dynamical systems.A system of nonlinear differential equations can always be expressed as a set of first order differential equations:
where t is (usually) time, x is the state vector, and f is a function that returns the state derivatives as a function of t and x.
ode23 integrates a system of ordinary differential equations using second and third order Runge-Kutta formulas. ode45 uses fourth and fifth order formulas.
The input arguments to ode23 and ode45 are
-------------------------------------------------------------------xprime A string variable with the name of the M-file that defines the differential equations to be integrated. The function needs to compute the state derivative vector, given the cur rent time and state vector. It must take two input argu ments, scalar t (time) and column vector x (state), and return output argument xdot, a column vector of state de rivatives: -------------------------------------------------------------------
-------------------------------------------------------------------t0 The starting time for the integration (initial value of t). tf The ending time for the integration (final value of t). x0 A column vector of initial conditions. tol Optional - the desired accuracy of the solution. The default value is 1.e-3 for ode23, 1.e-6 for ode45. trace Optional - flag to print intermediate results. The default value is 0 (don't trace). -------------------------------------------------------------------
Examples
Consider the second order differential equation known as the Van der Pol equation:You can rewrite this as a system of coupled first order differential equations:
The first step towards simulating this system is to create a function M-file containing these differential equations. Call it vdpol.m:
function xdot = vdpol(t,x)xdot = [x(1).*(1-x(2).^2)-x(2); x(1)]Note that ode23 requires this function to accept two inputs, t and x, although the function does not use the t input in this case.
To simulate the differential equation defined in vdpol over the interval 0 t ode23:
t0 = 0; tf = 20;x0 = [0 0.25]'; % Initial conditions[t,x] = ode23('vdpol',t0,tf,x0);plot(t,x)The general equations for a dynamical system are sometimes written as
where u is a time dependent vector of external inputs and y is a vector of final measured outputs of the system. Simulation of equations of this form are accomplished in the current framework by recognizing that u(t) can be formed within the xdot function, possibly using a global variable to hold a table of input values, and that y = g(x,t) is simply a final function application to the simulation results.
Algorithm
ode23 and ode45 are M-files that implement algorithms from [1]. On many systems, MEX-file versions are provided for speed.ode23 and ode45 are automatic step-size Runge-Kutta-Fehlberg integration methods. ode23 uses a simple second and third order pair of formulas for medium accuracy and ode45 uses a fourth and fifth order pair for higher accuracy.
Automatic step-size Runge-Kutta algorithms take larger steps where the solution is more slowly changing. Since ode45 uses higher order formulas, it usually takes fewer integration steps and gives a solution more rapidly. Interpolation (using interp1) can be used to give a smoother time history plot.
Diagnostics
If ode23 or ode45 cannot perform the integration over the full time range requested, it displays the messageSingularity likely.
See Also
odedemo, SIMULINK
References
[1] G.E. Forsythe, M.A. Malcolm and C.B. Moler, Computer Methods for Mathematical Computations, Prentice-Hall, 1977.(c) , Inc.