MATLAB: How to compute a problem that has some coupled parameters that are not computed as ODEs

coupledMATLABodeparameters

Best Answer

In order to compute a problem that has some coupled parameters that are not computed as ODEs, you need to incorporate it in the definition of the "odefun" function handle for the solvers "ode15s" and "ode23t" as differential-algebraic equations (DAEs).

In the example that you mentioned, you can modify the function handle definition as follows:

function dykdx  = mydae(x, yk)
    y = yk(1);
    k = yk(2);
    dykdx(1) = x + k.*y;
    dykdx(2) = x.^2 + y.^2; 
end

Further, the solution to the ODE can be solved using the commands:

>> Opts = odeset(‘Mass’, [1 0; 0 0],’MassSingular’,’yes’) ;
>> [X YK] = ode15s(@mydae, tspan, 1,Opts);

This will return both "y" and "k" computed via the same computation without needing to stop at each step.

However, there is a caveat that the solver offers no guarantees that the integration steps will match "tspan". Hence the values for "k" would be interpolated from the closest points, and not computed from the formula x.^2 + y.^2 applied to the interpolated x,y values.

Also, for multi-point "tspan", it would not be possible to reuse the values computed/cached within the derivative function at every point specified in "tspan". The solvers use variable integration steps and the solution at points specified in "tspan" is generally obtained by interpolation. In that case, the derivative function may not be called at those points in "tspan".