# Stiff Differential Equation solver (Euler?)

9 views (last 30 days)

Show older comments

Hello, I'm looking for a fixed-step integrating function capable of solving stiff differential equations, with a really small step size (below e-14).

Is this possible? Does MATLAB have one? I couldn't make it work with the built-in ode*() functions.

Anything out there available? Maybe working on the Euler method?

NLN

### Answers (2)

John D'Errico
on 7 Oct 2022

Edited: John D'Errico
on 7 Oct 2022

You SERIOUSLY do not want to use a standard Euler's method to solve a stiff ODE. You will be wasting your time. Why do you think you want to use Euler here, when better methods are available for stiff problems?

Worse, trying to use a step size of 1e-16 is just asking for numerical problems. This will NEVER be a good idea. Period.

Honestly, seriously, you do NOT want to use a simple forwards Euler method here. I don't know why you think you do. But you DON'T.

Having said all of that, the backwards Euler method is an option.

I won't write the code for you. But the backwards (implicit) Euler method should generally be stable for stiff problems. You may still need a fine step size, but 1e-16 is just obscene.

Do some reading before you proceed, if you really think you need to write this yourself.

Having said all of that, why in the name of god and little green apples do you want to write an ODE solver code yourself? This is especially true if you don't even know the basics of these codes? Use existing code when it is available. Do you think you will write better code than that from professionals who know very well how to do the numerical analysis? Never look to write your own code, unless it is a homework assignment.

In this case, you will want to use tools like ode15s or ode23s.

help ode15s

help ode23s

##### 5 Comments

John D'Errico
on 7 Oct 2022

Walter Roberson
on 8 Oct 2022

Code for fixed step solvers is at https://www.mathworks.com/matlabcentral/answers/98293-is-there-a-fixed-step-ordinary-differential-equation-ode-solver-in-matlab-8-0-r2012b#answer_107643

If this is not able to operate at a fine enough time step then you may need to alter the code to use the symbolic toolbox.

##### 1 Comment

Walter Roberson
on 8 Oct 2022

personally I think it likely that your equations, at least as implemented, have an unavoidable singularity.

- the equations might be wrong
- you might have coded them incorrectly
- the problem might possibly not be solvable using the techniques that you are using

I am a big fan of setting up the equations using the symbolic toolbox, which makes it much easier to follow the equations to be sure that they have been expressed correctly, especially if you use Livescript (better output format). Then use the work flow shown in the first example of odeFunction to convert the symbolic expressions for numeric solutions.

### See Also

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!