MATLAB: How to compute a problem that has some coupled parameters that are not computed as ODEs
coupledMATLABodeparameters
Related Question
- How to create a pictogram in MATLAB
- How to use custom date labels for the x-axis in MATLAB plots
- Can I change the properties of the confusion matrix plot like axes labels and tick labels
- How to add error bars to scatter plots
- Do “datenum” and “datestr” not give the same date after conversion
- Does the app freeze when loading data to a Table in App Designer and MATLAB R2017b
- Camera toolbar Reset button
- Can’t I find the “geographicToInstrinsic” function if I have the Mapping Toolbox installed
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:
Further, the solution to the ODE can be solved using the commands:
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".