Products & Services Solutions Academia Support User Community Company

Learn more about SimBiology   

About Simulation Solvers

How Solvers Work

In order to simulate a model, the model is converted to a set of differential equations. The solver functions are used to compute solutions for those equations at different time intervals, giving the model's states and outputs over a span of time. You can then plot these outputs from your simulation.

The MATLAB ODE solvers are designed to handle ordinary differential equations. An ordinary differential equation contains one or more derivatives of a dependent variable y with respect to a single independent variable t, usually referred to as time.

The solver functions implement numerical integration methods for solving initial value problems for ordinary differential equations (ODEs). Beginning at the initial time with initial conditions, they step through the time interval, computing a solution at each time step. If the solution for a time step satisfies the solver's error tolerance criteria, it is a successful step. Otherwise, it is a failed attempt; the solver shrinks the step size and tries again.

Stiff Versus Nonstiff Models

An ordinary differential equation problem is stiff if the solution being sought is varying slowly, but there are nearby solutions that vary rapidly, so the numerical method must take small steps to obtain satisfactory results. Many biological models are numerically stiff because they include species amounts that are changing quickly and others that change slowly.

Stiffness is an efficiency issue. In principle, nonstiff methods can solve stiff problems; they just take a long time to do it.

As an illustration, imagine trying to find the quickest descent through a canyon. An explicit algorithm, which is normally used for nonstiff models, would sample the local gradient to find the descent direction. But following the gradient on either side of the trail will send you bouncing back and forth from wall to wall — the descent will be found but it will take a long time. An implicit algorithm used for stiff models can anticipate where each step is taking you, keep you on the trail with fewer steps, and so save time. Using a stiff solver for a stiff problem can save thousands of solver steps and function evaluations compared to a nonstiff solver.

Methods intended to solve stiff problems efficiently do more work per step, but can take much bigger steps. Stiff methods are implicit. At each step they use MATLAB matrix operations to solve a system of simultaneous linear equations that helps predict the evolution of the solution.

Not all difficult problems are stiff, but all stiff problems are difficult for solvers not specifically designed for them. Solvers for stiff problems can be used exactly like the other solvers.

For an illustrative code example you can run to plot the effects of numerical stiffness on different solvers, see MATLAB News & Notes - May 2003 Cleve's Corner: Stiff Differential Equations.

Selecting a Solver

Choice of solver depends on the problem and time available for computation. There are trade-offs to be made between speed and accuracy. In general, ode45 is the best function to apply as a "first try" for most problems, or ode15s if you suspect that a problem is stiff. As you find out more about the problem you can try other solvers. Experimentation is generally required to determine the best solver for a particular model. As a general guide:

  1. Models with either all fast or all slow changing variables are nonstiff problems:

    Use Nonstiff Deterministic Solvers.

    • ode45 — Best first guess.

    • Sundials — Alternative best first guess. May be faster.

    • ode23 — May be more efficient than ode45 with crude tolerances and mild stiffness.

    • ode113 — May be more efficient than ode45 with stringent tolerances.

  2. Models with both fast and slow changing variables are stiff problems:

    Use Stiff Deterministic Solvers.

    • ode15s — Try first if you suspect that a problem is stiff, or if ode45 failed or was very inefficient.

    • Sundials — Alternative best first guess. May be faster.

    • ode23s — May be more efficient than ode15s at crude tolerances, and can solve some stiff problems that ode15s cannot.

    • ode23t — Use this solver if the problem is only moderately stiff and you need a solution without numerical damping.

    • ode23tb — Like ode23s, this solver may be more efficient than ode15s at crude tolerances.

  3. Models with a small number of molecules:

    Use Stochastic Solvers.

    • Stochastic — Most accurate, may be too slow if the initial number of molecules for a reactant species is large.

    • Explicit Tau — Speeds up the simulation at the cost of some accuracy; can be orders of magnitude faster than Stochastic. Can be used for large problems (provided the problem is not numerically stiff).

    • Implicit Tau — May be the fastest, at the cost of some accuracy. Can be used for large problems and also for numerically stiff problems. For nonstiff systems may not be a good choice because it adds computational overhead.

    If you use a stochastic solver to simulate a model, the software ignores any rate, assignment, or algebraic rules if present in the model.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS