Skip to content
MathWorks - Mobile View
  • Melden Sie sich bei Ihrem MathWorks Konto anMelden Sie sich bei Ihrem MathWorks Konto an
  • Access your MathWorks Account
    • Eigener Account
    • Mein Community Profil
    • Lizenz zuordnen
    • Abmelden
  • Produkte
  • Lösungen
  • Forschung und Lehre
  • Support
  • Community
  • Veranstaltungen
  • MATLAB erhalten
MathWorks
  • Produkte
  • Lösungen
  • Forschung und Lehre
  • Support
  • Community
  • Veranstaltungen
  • MATLAB erhalten
  • Melden Sie sich bei Ihrem MathWorks Konto anMelden Sie sich bei Ihrem MathWorks Konto an
  • Access your MathWorks Account
    • Eigener Account
    • Mein Community Profil
    • Lizenz zuordnen
    • Abmelden

Videos und Webinare

  • MathWorks
  • Videos
  • Videos Homepage
  • Suche
  • Videos Homepage
  • Suche
  • Vertrieb kontaktieren
  • Testsoftware
6:46 Video length is 6:46.
  • Description
  • Full Transcript
  • Code and Resources

Solving ODEs in MATLAB, 6: ODE45

From the series: Solving ODEs in MATLAB

ODE45 is usually the function of choice among the ODE solvers. It compares methods of orders four and five to estimate error and determine step size. ODE45 is so accurate that its default behavior is to use its interpolant to provide results at intermediate points.

Related MATLAB code files can be downloaded from MATLAB Central

 

The most frequently used ODE solver in MATLAB and Simulink is ODE45. It is based on method published by British mathematicians JR Dormand and PJ Prince in 1980. The basic method is order five. The error correction uses a companion order four method.

The slope of tn is, first same as last left over from the previous successful step. Then there are five more slopes from function values at 1/5 h, 3/10h, 4/5h, 8/9h and then at tn plus 1. These six slopes, linear combinations of them, are used to produce yn plus 1.

The function is evaluated at tn plus 1 and yn plus 1 to get a seventh slope. And then linear combinations of these are used to produce the error estimate.

Again, if the error estimate is less than the specified accuracy requirements the step is successful. And then that error estimate is used to get the next step size. If the error is too big, the step is unsuccessful and that error estimate is used to get the step size to do the step over again.

If we want to see the actual coefficients that are used, you can go into the code for ODE45. There's a table with the coefficients. Or you go to the Wikipedia page for the Dormand-Prince Method and there is the same coefficients.

As an aside, here is an interesting fact about higher order Runge-Kutta methods. Classical Runge-Kutta required four function evaluations per step to get order four. Dormand-Prince requires six function evaluations per step to get order five. You can't get order five with just five function evaluations. And then, if we were to try and achieve higher order, it would take even more function evaluations per step.

Let's use ODE45 to compute e to the t. y prime is equal to y. We can ask for output by supplying an argument called tspan. Zero and steps of 0.1 to 1. If we supply that as the input argument to solve this differential equation and get the output at those points, we get that back as the output. And now here's the approximations to the solution to that differential equation at those points.

If we plot it, here's the solution at those points. And to see how accurate it is, we see that we're actually getting this result to nine digits. ODE45 is very accurate.

Let's look at step size choice on our problem with near singularity, is a quarter. y0 is close to 16. The differential equation is y prime is 2(a-t) y squared. We let ODE45 choose its own step size by indicating we just want to integrate from 0 to 1. We capture the output in t and y and plot it.

Now, here, there's a lot of points here, but this is misleading because ODE45, by default, is using the refine option. It's only actually evaluating the function at every fourth one of these points and then using the interpolant to fill in in between. So we actually need a little different plot here.

This plot shows a little better what's going on. The big dots are the points that ODE45 chose to evaluate the differential equation. And the little dots are filled in with the interpolant. So the big dots are every fourth point. And the refine option says that the big dots are too far apart and we need to fill it in with the interpolant. And so this is the continuous interpolant in action.

The big dots are more closely concentrated as we have to go around the curve. And then, as we get farther away from the singularity the step size increases. So this shows the high accuracy of ODE45 and the automatic step size choice in action.

Here's an exercise. Compare ODE23 and ODE45 by using each of them to compute pi. The integral 4 over 1 plus t squared from 0 to 1 is pi. You can express that as a differential equation, use each of the routines to integrate that differential equation and see how close they get to computing pi.

Download Code and Files

Download the code in this video

Related Products

  • MATLAB

Learn More

Explore more resources from Cleve Moler

Bridging Wireless Communications Design and Testing with MATLAB

Read white paper
Related Information
Learn differential equations

Feedback

Featured Product

MATLAB

  • Request Trial
  • Get Pricing

Up Next:

A problem is said to be stiff if the solution being sought varies slowly, but there are nearby solutions that vary rapidly, so the numerical method must take small steps to obtain satisfactory results. The flame model demonstrates stiffness.
7:14
7: Stiffness, ODE23s, ODE15s
View full series (12 Videos)

Related Videos:

5:34
Solving ODEs in MATLAB, 9: The MATLAB ODE Suite
14:16
Solving ODEs in MATLAB, 11: Predator-Prey Equations
14:16
Solving ODEs in MATLAB, 8: Systems of Equations
15:21
Solving ODEs in MATLAB, 1: Euler, ODE1
9:37
Solving ODEs in MATLAB, 3: Classical Runge-Kutta, ODE4

View more related videos

MathWorks - Domain Selector

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

  • Switzerland (English)
  • Switzerland (Deutsch)
  • Switzerland (Français)
  • 中国 (简体中文)
  • 中国 (English)

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

  • Vertrieb kontaktieren
  • Testsoftware

MathWorks

Accelerating the pace of engineering and science

MathWorks ist der führende Entwickler von Software für mathematische Berechnungen für Ingenieure und Wissenschaftler.

Entdecken Sie…

Produkte

  • MATLAB
  • Simulink
  • Software für Studierende
  • Hardware-Unterstützung
  • File Exchange

Testen oder Kaufen

  • Downloads
  • Testsoftware
  • Vertrieb kontaktieren
  • Preise und Lizenzierung
  • Store

Lernen

  • Dokumentation
  • Tutorials
  • Beispiele
  • Videos und Webinare
  • Schulungen

Support

  • Hilfe zur Installation
  • MATLAB Answers
  • Consulting
  • License Center
  • Support kontaktieren

Über MathWorks

  • Jobs & Karriere
  • Newsroom
  • Soziales Engagement
  • Berichte von Anwendern
  • Über MathWorks
  • Select a Web Site United States
  • Trust Center
  • Handelsmarken
  • Datenschutz
  • Datendiebstahl verhindern
  • Status von Anwendungen

© 1994-2022 The MathWorks, Inc.

  • Facebook
  • Twitter
  • Instagram
  • YouTube
  • LinkedIn
  • RSS

Folgen Sie uns