odeMassMatrix

Mass matrix definition for an ode object, for problems M y' = f(t, y).

Category: Other public functions: funfun

Syntax

M = odeMassMatrix(MassMatrix=A)

Uses a constant matrix A as the mass matrix.

M = odeMassMatrix(MassMatrix=fcn, StateDependence=sd)

Uses a function handle for a time or state dependent mass matrix.

Description

Some models come naturally as M*y' = f(t, y) with a matrix M on the left, for example when conservation laws mix the states. Passing M lets the solver handle that form directly instead of requiring an inverse. When M is singular, some equations are algebraic constraints and the problem is differential-algebraic, which only some solvers (such as ode15s) accept.

Input arguments

MassMatrix
Square matrix, or a function handle returning one.
Singular
'yes' for a differential-algebraic system whose matrix is singular; 'no' by default.
StateDependence
'none' (default), 'weak' or 'strong'.

Output arguments

M
An odeMassMatrix object, assigned to the MassMatrix property of an ode object.

Example

Scaled equations

M = odeMassMatrix(MassMatrix=[2 0; 0 1]);
f = ode(ODEFcn=@(t, y) -y, InitialValue=[1; 1], MassMatrix=M);
sol = solve(f, 0, 1);
fprintf('%.4f %.4f\n', sol.Solution(:, end))
fprintf('%.4f %.4f\n', exp(-0.5), exp(-1))
Output
0.6065 0.3677
0.6065 0.3679

See also

ode odeEvent odeJacobian ode15s odeset