MathWorks - Mobile View
  • MathWorks 㚢㚫㚦㒳㒆への㚵㚤㒳㚤㒳MathWorks 㚢㚫㚦㒳㒆への㚵㚤㒳㚤㒳
  • Access your MathWorks Account
    • マイ アカウント
    • コミュニティのプロファイル
    • ライセンスを関連付ける
    • サインアウト
  • 製品
  • ソリューション
  • アカデミア
  • サポート
  • コミュニティ
  • イベント
  • MATLAB を入手する
MathWorks
  • 製品
  • ソリューション
  • アカデミア
  • サポート
  • コミュニティ
  • イベント
  • MATLAB を入手する
  • MathWorks 㚢㚫㚦㒳㒆への㚵㚤㒳㚤㒳MathWorks 㚢㚫㚦㒳㒆への㚵㚤㒳㚤㒳
  • Access your MathWorks Account
    • マイ アカウント
    • コミュニティのプロファイル
    • ライセンスを関連付ける
    • サインアウト

ビデオ・Webセミナー

  • MathWorks
  • ビデオ
  • ビデオ ホーム
  • 検索
  • ビデオ ホーム
  • 検索
  • 営業へのお問い合わせ
  • 評価版
  Register to watch video
  • Description
  • Full Transcript
  • Code and Resources

Solving ODEs in MATLAB, 6: ODE45

From the series: Solving ODEs in MATLAB

Cleve Moler, MathWorks

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
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
15:21
Solving ODEs in MATLAB, 1: Euler, ODE1
9:51
Solving ODEs in MATLAB, 10: Tumbling Box
14:16
Solving ODEs in MATLAB, 11: Predator-Prey Equations
10:24
Solving ODEs in MATLAB, 12: Lorenz Attractor and Chaos

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: .

Select web site

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

  • 営業へのお問い合わせ
  • 評価版

製品を見る

  • MATLAB
  • Simulink
  • 学生向けソフトウェア
  • ハードウェア サポート
  • File Exchange
試す、購入する
  • ダウンロード
  • 評価版ソフトウェア
  • 営業へのお問い合わせ
  • 価格とライセンス
使い方を学ぶ
  • ドキュメンテーション
  • チュートリアル
  • MATLAB の例
  • ビデオ・Webセミナー
  • トレーニング

サポートを受ける

  • インストールのヘルプ
  • MATLAB Answers
  • 技術コンサルティング
  • ライセンスセンター
  • サポートへのお問い合わせ

MathWorks について

  • 採用情報
  • ニュースルーム
  • 社会貢献
  • 営業へのお問い合わせ
  • MathWorks について

MathWorks

Accelerating the pace of engineering and science

MathWorksはエンジニアや研究者向け数値解析ソフトウェアのリーディングカンパニーです。

ディスカバー…

  • Select a Web Site United States
  • 特許
  • 商標
  • プライバシー ポリシー
  • 違法コピー防止
  • アプリケーション ステータス

© 1994-2021 The MathWorks, Inc.

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

MATLAB を語ろう