Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > b38d2da330d1936e5ab1307c039c4941 > files > 387

octave-doc-3.6.4-3.mga4.noarch.rpm

<html lang="en">
<head>
<title>Ordinary Differential Equations - GNU Octave</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Octave">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Differential-Equations.html#Differential-Equations" title="Differential Equations">
<link rel="next" href="Differential_002dAlgebraic-Equations.html#Differential_002dAlgebraic-Equations" title="Differential-Algebraic Equations">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Ordinary-Differential-Equations"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Differential_002dAlgebraic-Equations.html#Differential_002dAlgebraic-Equations">Differential-Algebraic Equations</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Differential-Equations.html#Differential-Equations">Differential Equations</a>
<hr>
</div>

<h3 class="section">24.1 Ordinary Differential Equations</h3>

<p>The function <code>lsode</code> can be used to solve ODEs of the form

<pre class="example">     dx
     -- = f (x, t)
     dt
</pre>
   <p class="noindent">using Hindmarsh's ODE solver <span class="sc">lsode</span>.

<!-- lsode src/DLD-FUNCTIONS/lsode.cc -->
   <p><a name="doc_002dlsode"></a>

<div class="defun">
&mdash; Loadable Function: [<var>x</var>, <var>istate</var>, <var>msg</var>] = <b>lsode</b> (<var>fcn, x_0, t</var>)<var><a name="index-lsode-2346"></a></var><br>
&mdash; Loadable Function: [<var>x</var>, <var>istate</var>, <var>msg</var>] = <b>lsode</b> (<var>fcn, x_0, t, t_crit</var>)<var><a name="index-lsode-2347"></a></var><br>
<blockquote><p>Solve the set of differential equations

     <pre class="example">          dx
          -- = f(x, t)
          dt
</pre>
        <p class="noindent">with

     <pre class="example">          x(t_0) = x_0
</pre>
        <p>The solution is returned in the matrix <var>x</var>, with each row
corresponding to an element of the vector <var>t</var>.  The first element
of <var>t</var> should be t_0 and should correspond to the initial
state of the system <var>x_0</var>, so that the first row of the output
is <var>x_0</var>.

        <p>The first argument, <var>fcn</var>, is a string, inline, or function handle
that names the function f to call to compute the vector of right
hand sides for the set of equations.  The function must have the form

     <pre class="example">          <var>xdot</var> = f (<var>x</var>, <var>t</var>)
</pre>
        <p class="noindent">in which <var>xdot</var> and <var>x</var> are vectors and <var>t</var> is a scalar.

        <p>If <var>fcn</var> is a two-element string array or a two-element cell array
of strings, inline functions, or function handles, the first element names
the function f described above, and the second element names a
function to compute the Jacobian of f.  The Jacobian function
must have the form

     <pre class="example">          <var>jac</var> = j (<var>x</var>, <var>t</var>)
</pre>
        <p class="noindent">in which <var>jac</var> is the matrix of partial derivatives

     <pre class="example">                       | df_1  df_1       df_1 |
                       | ----  ----  ...  ---- |
                       | dx_1  dx_2       dx_N |
                       |                       |
                       | df_2  df_2       df_2 |
                       | ----  ----  ...  ---- |
                df_i   | dx_1  dx_2       dx_N |
          jac = ---- = |                       |
                dx_j   |  .    .     .    .    |
                       |  .    .      .   .    |
                       |  .    .       .  .    |
                       |                       |
                       | df_N  df_N       df_N |
                       | ----  ----  ...  ---- |
                       | dx_1  dx_2       dx_N |
</pre>
        <p>The second and third arguments specify the initial state of the system,
x_0, and the initial value of the independent variable t_0.

        <p>The fourth argument is optional, and may be used to specify a set of
times that the ODE solver should not integrate past.  It is useful for
avoiding difficulties with singularities and points where there is a
discontinuity in the derivative.

        <p>After a successful computation, the value of <var>istate</var> will be 2
(consistent with the Fortran version of <span class="sc">lsode</span>).

        <p>If the computation is not successful, <var>istate</var> will be something
other than 2 and <var>msg</var> will contain additional information.

        <p>You can use the function <code>lsode_options</code> to set optional
parameters for <code>lsode</code>. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002ddaspk.html#doc_002ddaspk">daspk</a>, <a href="doc_002ddassl.html#doc_002ddassl">dassl</a>, <a href="doc_002ddasrt.html#doc_002ddasrt">dasrt</a>. 
</p></blockquote></div>

<!-- lsode_options src/DLD-FUNCTIONS/lsode.cc -->
   <p><a name="doc_002dlsode_005foptions"></a>

<div class="defun">
&mdash; Loadable Function:  <b>lsode_options</b> ()<var><a name="index-lsode_005foptions-2348"></a></var><br>
&mdash; Loadable Function: val = <b>lsode_options</b> (<var>opt</var>)<var><a name="index-lsode_005foptions-2349"></a></var><br>
&mdash; Loadable Function:  <b>lsode_options</b> (<var>opt, val</var>)<var><a name="index-lsode_005foptions-2350"></a></var><br>
<blockquote><p>Query or set options for the function <code>lsode</code>. 
When called with no arguments, the names of all available options and
their current values are displayed. 
Given one argument, return the value of the corresponding option. 
When called with two arguments, <code>lsode_options</code> set the option
<var>opt</var> to value <var>val</var>.

        <p>Options include

          <dl>
<dt><code>"absolute tolerance"</code><dd>Absolute tolerance.  May be either vector or scalar.  If a vector, it
must match the dimension of the state vector.

          <br><dt><code>"relative tolerance"</code><dd>Relative tolerance parameter.  Unlike the absolute tolerance, this
parameter may only be a scalar.

          <p>The local error test applied at each integration step is

          <pre class="example">                 abs (local error in x(i)) &lt;= ...
                     rtol * abs (y(i)) + atol(i)
</pre>
          <br><dt><code>"integration method"</code><dd>A string specifying the method of integration to use to solve the ODE
system.  Valid values are

               <dl>
<dt>"adams"<dt>"non-stiff"<dd>No Jacobian used (even if it is available).

               <br><dt>"bdf"<dt>"stiff"<dd>Use stiff backward differentiation formula (BDF) method.  If a
function to compute the Jacobian is not supplied, <code>lsode</code> will
compute a finite difference approximation of the Jacobian matrix. 
</dl>

          <br><dt><code>"initial step size"</code><dd>The step size to be attempted on the first step (default is determined
automatically).

          <br><dt><code>"maximum order"</code><dd>Restrict the maximum order of the solution method.  If using the Adams
method, this option must be between 1 and 12.  Otherwise, it must be
between 1 and 5, inclusive.

          <br><dt><code>"maximum step size"</code><dd>Setting the maximum stepsize will avoid passing over very large
regions  (default is not specified).

          <br><dt><code>"minimum step size"</code><dd>The minimum absolute step size allowed (default is 0).

          <br><dt><code>"step limit"</code><dd>Maximum number of steps allowed (default is 100000). 
</dl>
        </p></blockquote></div>

   <p>Here is an example of solving a set of three differential equations using
<code>lsode</code>.  Given the function

   <p><a name="index-oregonator-2351"></a>
<pre class="example">     function xdot = f (x, t)
     
       xdot = zeros (3,1);
     
       xdot(1) = 77.27 * (x(2) - x(1)*x(2) + x(1) \
                 - 8.375e-06*x(1)^2);
       xdot(2) = (x(3) - x(1)*x(2) - x(2)) / 77.27;
       xdot(3) = 0.161*(x(1) - x(3));
     
     endfunction
</pre>
   <p class="noindent">and the initial condition <code>x0 = [ 4; 1.1; 4 ]</code>, the set of
equations can be integrated using the command

<pre class="example">     t = linspace (0, 500, 1000);
     
     y = lsode ("f", x0, t);
</pre>
   <p>If you try this, you will see that the value of the result changes
dramatically between <var>t</var> = 0 and 5, and again around <var>t</var> = 305. 
A more efficient set of output points might be

<pre class="example">     t = [0, logspace (-1, log10(303), 150), \
             logspace (log10(304), log10(500), 150)];
</pre>
   <p>See Alan C. Hindmarsh, <cite>ODEPACK, A Systematized Collection of ODE
Solvers</cite>, in Scientific Computing, R. S. Stepleman, editor, (1983) for
more information about the inner workings of <code>lsode</code>.

   </body></html>