1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Integrating Differential Equations (GNU Octave (version 10.3.0))</title>
<meta name="description" content="Integrating Differential Equations (GNU Octave (version 10.3.0))">
<meta name="keywords" content="Integrating Differential Equations (GNU Octave (version 10.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Simple-Examples.html" rel="up" title="Simple Examples">
<link href="Producing-Graphical-Output.html" rel="next" title="Producing Graphical Output">
<link href="Solving-Systems-of-Linear-Equations.html" rel="prev" title="Solving Systems of Linear Equations">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<div class="subsection-level-extent" id="Integrating-Differential-Equations">
<div class="nav-panel">
<p>
Next: <a href="Producing-Graphical-Output.html" accesskey="n" rel="next">Producing Graphical Output</a>, Previous: <a href="Solving-Systems-of-Linear-Equations.html" accesskey="p" rel="prev">Solving Systems of Linear Equations</a>, Up: <a href="Simple-Examples.html" accesskey="u" rel="up">Simple Examples</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Integrating-Differential-Equations-1"><span>1.2.5 Integrating Differential Equations<a class="copiable-link" href="#Integrating-Differential-Equations-1"> ¶</a></span></h4>
<p>Octave has built-in functions for solving nonlinear differential
equations of the form
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">dx
-- = f (x, t)
dt
</pre></div></div>
<p>with the initial condition
</p>
<div class="example">
<pre class="example-preformatted">x(t = t0) = x0
</pre></div>
<p>For Octave to integrate equations of this form, you must first provide a
definition of the function
<code class="code">f(x,t)</code>.
This is straightforward, and may be accomplished by entering the
function body directly on the command line. For example, the following
commands define the right-hand side function for an interesting pair of
nonlinear differential equations. Note that while you are entering a
function, Octave responds with a different prompt, to indicate that it
is waiting for you to complete your input.
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">octave:1> function xdot = f (x, t)
>
> r = 0.25;
> k = 1.4;
> a = 1.5;
> b = 0.16;
> c = 0.9;
> d = 0.8;
>
> xdot(1) = r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1));
> xdot(2) = c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2);
>
> endfunction
</pre></div></div>
<p>Given the initial condition
</p>
<div class="example">
<pre class="example-preformatted">octave:2> x0 = [1; 2];
</pre></div>
<p>and the set of output times as a column vector (note that the first
output time corresponds to the initial condition given above)
</p>
<div class="example">
<pre class="example-preformatted">octave:3> t = linspace (0, 50, 200)';
</pre></div>
<p>it is easy to integrate the set of differential equations:
</p>
<div class="example">
<pre class="example-preformatted">octave:4> x = lsode ("f", x0, t);
</pre></div>
<p>The function <code class="code">lsode</code> uses the Livermore Solver for Ordinary
Differential Equations, described in A. C. Hindmarsh,
<cite class="cite">ODEPACK, a Systematized Collection of ODE Solvers</cite>, in: Scientific
Computing, R. S. Stepleman et al. (Eds.), North-Holland, Amsterdam,
1983, pages 55–64.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Producing-Graphical-Output.html">Producing Graphical Output</a>, Previous: <a href="Solving-Systems-of-Linear-Equations.html">Solving Systems of Linear Equations</a>, Up: <a href="Simple-Examples.html">Simple Examples</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|