Please post a copy of the complete error message and mention the line, which causes the error. If "line 8" is dy(2)=sign(y(1))*dy(3);, this would be very strange, because the variable y is used in if abs(y(1))-(Q*(1-exp(-b*y(3))))-sigma0<0 already.

Therefore I guess, some standard bugs are responsible. Did you shadow a built-in function by a script, which contains a clear all? To check this, set a breakpoint in the function f_iso and step through the code line by line trying to jump into subfunctions, e.g. by the F11 key.

Btw., the function to be integrated must be smooth, otherwise the step-size control of ODE45 can lead to unexpected effects:

- ODE45 integrates right over the discontinuity without noticing this. Then the result has a poor accuracy only.
- ODE45 finds the discontinuity and stops with a warning message "Unable to meet integration tolerances without reducing the step size below the smallest value allowed".
- ODE45 reduces the step size to such a tiny value, that the integration takes hours to run and the accumulated rounding error dominates the solution. This is exactly what the step size control should avoid.

Which of these cases happens can depend on minimal variations of the initial values or parameters, and therefore this must be treated as a bug. Use an event function to toggle values of a parameter.

[EDITED] Some references:

The last one explains a method to let a DOPRI45 detect and handle a discontinuity. It would be a nice enhancement for Matlab's ODE45. It could be expanded to handle parameter changes triggered by event functions without the need to restart the integration.

## 0 Comments

Sign in to comment.