# numeric::odeToVectorField

Convert an ode system to vectorfield notation

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

numeric::odeToVectorField(IVP, fields)

## Description

numeric::odeToVectorField converts a system of ordinary differential equations of arbitrary order to a vector field representation suitable for the numerical ODE solver numeric::odesolve2.

numeric::odeToVectorField and numeric::ode2vectorfield are equivalent.

numeric::odeToVectorField is a utility function to generate input parameters for the numerical ODE solver numeric::odesolve2. This solver requires a procedure representing the vectorfield f(t, Y) of a first order system of differential equations (dynamic system) and initial data Y0 = Y(t0). Given an initial value problem IVP consisting of (possibly higher order) differential expressions together with initial conditions, numeric::odeToVectorField converts the higher order equations to an equivalent system of first order ODEs and returns the input parameters for numeric::odesolve2.

Higher-order differential equations can always be represented as an equivalent dynamic system with some vector Y. E.g., the n-th order equation

may be written as the first order system

for the vector .

The input list fields correponds to the vector Y. It must be a complete specification of all functions and their derivatives through but not including the highest derivates of the unknown functions. E.g., for the second order differential equation , the appropriate list of unknown fields is . The differential equations are of second order in y and of first order in z. Hence, the appropriate list of unknown fields is [y(t), y'(t), z(t)].

The ordering of the fields in list determines the ordering of the components of the list that the numerical solver produces as the solution vector. Cf. Example 2.

The differential equations must be linear in the highest derivatives of the unknown functions involved. E.g., the ODE is not admitted. However, equations such as are accepted and converted to .

A complete specification of initial conditions must be contained in IVP: for each component in list, an initial value must be provided. The initial conditions may be specified by linear equations which will be solved for the initial values of the unknown fields automatically. E.g., for fields = [y(t), y'(t), z(t)], initial conditions may be specified explicitly by y(t0) = 1, y'(t_0) = 2, z(t0) = 3, say, or via linear equations such as y(t_0) + z(t_0) = y'(t_0), y(t0) = z(t0), z(t0) = 2 y(t0). Cf. Example 3.

The differential equations, the initial ‘time' t0, and the initial conditions may involve symbolic parameters. However, such parameters must evaluate to numerical objects, when the sequence returned by numeric::odeToVectorField is passed to the numerical solver.

The vectorfield procedure f and the initial values Y0 returned by numeric::odeToVectorField can also be used by the functions numeric::odesolve, plot::Ode2d, plot::Ode3d. Cf. Example 3.

## Examples

### Example 1

We consider the initial value problem

.

The solver numeric::odesolve2 requires the procedure f: for the 1-dimensional vector Y = [y(t)] specified by fields. The utility numeric::ode2vectorfield accepts a more convenient representation via arithmetical expressions:

IVP := {y'(t) = t*sin(y(t)), y(t0) = y0}:
fields := [y(t)]:
IVP := numeric::ode2vectorfield(IVP, fields)

This sequence may be passed to the numerical solver which returns a procedure representing the numerical solution:

t0 := 0: y0 := 1:
Y := numeric::odesolve2(IVP)

Calling the numerical solution Y invokes the numerical integration from the intial ‘time' t0 = 0 to the ‘time' specified in the call to Y:

Y(0), Y(1), Y(2), Y(3)

delete IVP, fields, Y:

### Example 2

We consider the second order initial value problem

.

The corresponding vectorfield representation involves the vector specified by fields:

IVP := {y''(t) = t*sin(y(t)), y(0) = 1, y'(0) = 0}:
fields := [y(t), y'(t)]:
numeric::ode2vectorfield(IVP, fields)

This sequence is accepted by numeric::odesolve2. The numerical solution Y returns lists representing the components of the vector specified by fields:

Y := numeric::odesolve2(%):
Y(5)

With a reordering of the unknown fields, the numerical solver returns the solution vector with rearranged components:

fields := [y'(t), y(t)]:
Y := numeric::odesolve2(numeric::ode2vectorfield(IVP, fields)):
Y(5)

delete IVP, fields, Y:

### Example 3

The following IVP involves the unknown fields u(t), v(t), w(t). Since it is of second order in u, of first order in v and of third order in w, the list of unknowns [y(t), y'(t), v(t), w(t), w'(t), w''(t)] is appropriate:

IVP := {u''(t) - u(t)*v'(t) = exp(-t)*v'(t), v'(t) = w''(t),
u'(t)*w'''(t) = t + u''(t),
u(PI) = 3, u'(PI) = 1,
v(PI) = 0,
w(PI) = w'(PI), w'(PI) = 2 - w(PI), w''(PI) = 3*w(PI)}:
fields := [u(t), u'(t), v(t), w(t), w'(t), w''(t)]:
ivp := numeric::ode2vectorfield(IVP, fields)

Y := numeric::odesolve2(ivp):
Y(5)

We plot the components v, w, and of the solution vector:

plotfunc2d(Y(t)[3], Y(t)[4], Y(t)[6], t = PI .. 5,
Colors = [RGB::Red, RGB::Green, RGB::Blue]):

Alternatively, we use the vectorfield procedure ivp[1] and the initial conditions ivp[3] as input parameters for plot::Ode2d:

plot(plot::Ode2d([PI + i*(5 - PI)/30 \$ i = 0..30],
ivp[1], ivp[3],
[(t, Y) -> [t, Y[3]], Color = RGB::Red],
[(t, Y) -> [t, Y[4]], Color = RGB::Green],
[(t, Y) -> [t, Y[6]], Color = RGB::Blue])):

delete IVP, fields, ivp, Y:

## Parameters

 IVP The initial value problem: a list or a set of equations involving univariate function calls y1(t), y2(t) etc. and derivates , , …, , etc. The differential equations must be quasi-linear: the highest derivative of each of the dependent functions y1(t), y2(t) etc. must enter the equations linearly. IVP must also contain corresponding initial conditions specified by linear equations in the expressions y1(t0), , …, y2(t0), etc. Alternatively, arithmetical expressions may be specified which are interpreted as equations with vanishing right hand side. fields The vector of the dynamical system equivalent to IVP: a list of symbolic function calls such as [y_1(t), y_1'(t), dots, y_2(t), y_2'(t), dots] representing the unknown fields to be solved for.

## Return Values

Sequence f, t0, Y0. These data represent the dynamical system with the initial condition Y(t0) = Y0 equivalent to IVP. The vectorfield f: is a procedure, t0 is a numerical expression representing the initial ‘time', and Y0 is a list of numerical expressions representing the components of the initial vector Y0.