# Stiff Differential Equation solver (Euler?)

5 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

##### 14 Comments

Torsten
on 8 Oct 2022

Edited: Torsten
on 8 Oct 2022

If "information" in "StraightRun" is a row vector,

for i = 1:numel(T)

[~, information(i,:)] = StraightRun(T(i),Y(i,:));

end

Of course, your function StraightRun must have the form

function [dy,information] = StraightRun(t,y)

I hope all variables involved (V_A,beta_A,alpha_S,X,Y,N,X_AS,Y_AS,N_AS) are scalar values.

### 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!