File: Matlab_002dcompatible-solvers.html

package info (click to toggle)
octave 6.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 124,192 kB
  • sloc: cpp: 322,665; ansic: 68,088; fortran: 20,980; objc: 8,121; sh: 7,719; yacc: 4,266; lex: 4,123; perl: 1,530; java: 1,366; awk: 1,257; makefile: 424; xml: 147
file content (753 lines) | stat: -rw-r--r-- 39,622 bytes parent folder | download
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Matlab-compatible solvers (GNU Octave (version 6.2.0))</title>

<meta name="description" content="Matlab-compatible solvers (GNU Octave (version 6.2.0))">
<meta name="keywords" content="Matlab-compatible solvers (GNU Octave (version 6.2.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<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="Ordinary-Differential-Equations.html" rel="up" title="Ordinary Differential Equations">
<link href="Differential_002dAlgebraic-Equations.html" rel="next" title="Differential-Algebraic Equations">
<link href="Ordinary-Differential-Equations.html" rel="prev" title="Ordinary Differential Equations">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<span id="Matlab_002dcompatible-solvers"></span><div class="header">
<p>
Up: <a href="Ordinary-Differential-Equations.html" accesskey="u" rel="up">Ordinary Differential Equations</a> &nbsp; [<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>
<span id="Matlab_002dcompatible-solvers-1"></span><h4 class="subsection">24.1.1 Matlab-compatible solvers</h4>

<p>Octave also provides a set of solvers for initial value problems for ordinary
differential equations (ODEs) that have a <small>MATLAB</small>-compatible interface.
The options for this class of methods are set using the functions.
</p>
<ul>
<li> <a href="#XREFodeset">odeset</a>

</li><li> <a href="#XREFodeget">odeget</a>
</li></ul>

<p>Currently implemented solvers are:
</p>
<ul>
<li> Runge-Kutta methods

<ul>
<li> <a href="#XREFode45">ode45</a> integrates a system of non-stiff ODEs or
    index-1 differential-algebraic equations (DAEs) using the high-order,
    variable-step Dormand-Prince method.  It requires six function
    evaluations per integration step, but may take larger steps on smooth
    problems than <code>ode23</code>: potentially offering improved efficiency at
    smaller tolerances.

</li><li> <a href="#XREFode23">ode23</a> integrates a system of non-stiff ODEs or (or
    index-1 DAEs).  It uses the third-order Bogacki-Shampine method
    and adapts the local step size in order to satisfy a user-specified
    tolerance.  The solver requires three function evaluations per integration
    step.

</li><li> <a href="#XREFode23s">ode23s</a> integrates a system of stiff ODEs (or
    index-1 DAEs) using a modified second-order Rosenbrock method.
  </li></ul>

</li><li> Linear multistep methods

<ul>
<li> <a href="#XREFode15s">ode15s</a> integrates a system of stiff ODEs (or
    index-1 DAEs) using a variable step, variable order method based on
    Backward Difference Formulas (BDF).

</li><li> <a href="#XREFode15i">ode15i</a> integrates a system of fully-implicit ODEs
    (or index-1 DAEs) using the same variable step, variable order method as
    <code>ode15s</code>.  <a href="#XREFdecic">decic</a> can be used to compute consistent
    initial conditions for <code>ode15i</code>.
  </li></ul>
</li></ul>

<p>Detailed information on the solvers are given in L. F. Shampine and
M. W. Reichelt, <cite>The MATLAB ODE Suite</cite>, SIAM Journal on
Scientific Computing, Vol. 18, 1997, pp. 1–22.
</p>
<span id="XREFode45"></span><dl>
<dt id="index-ode45">: <em>[<var>t</var>, <var>y</var>] =</em> <strong>ode45</strong> <em>(<var>fun</var>, <var>trange</var>, <var>init</var>)</em></dt>
<dt id="index-ode45-1">: <em>[<var>t</var>, <var>y</var>] =</em> <strong>ode45</strong> <em>(<var>fun</var>, <var>trange</var>, <var>init</var>, <var>ode_opt</var>)</em></dt>
<dt id="index-ode45-2">: <em>[<var>t</var>, <var>y</var>, <var>te</var>, <var>ye</var>, <var>ie</var>] =</em> <strong>ode45</strong> <em>(&hellip;)</em></dt>
<dt id="index-ode45-3">: <em><var>solution</var> =</em> <strong>ode45</strong> <em>(&hellip;)</em></dt>
<dt id="index-ode45-4">: <em></em> <strong>ode45</strong> <em>(&hellip;)</em></dt>
<dd>
<p>Solve a set of non-stiff Ordinary Differential Equations (non-stiff ODEs)
with the well known explicit Dormand-Prince method of order 4.
</p>
<p><var>fun</var> is a function handle, inline function, or string containing the
name of the function that defines the ODE: <code>y' = f(t,y)</code>.  The function
must accept two inputs where the first is time <var>t</var> and the second is a
column vector of unknowns <var>y</var>.
</p>
<p><var>trange</var> specifies the time interval over which the ODE will be
evaluated.  Typically, it is a two-element vector specifying the initial and
final times (<code>[tinit, tfinal]</code>).  If there are more than two elements
then the solution will also be evaluated at these intermediate time
instances.
</p>
<p>By default, <code>ode45</code> uses an adaptive timestep with the
<code>integrate_adaptive</code> algorithm.  The tolerance for the timestep
computation may be changed by using the options <code>&quot;RelTol&quot;</code> and
<code>&quot;AbsTol&quot;</code>.
</p>
<p><var>init</var> contains the initial value for the unknowns.  If it is a row
vector then the solution <var>y</var> will be a matrix in which each column is
the solution for the corresponding initial value in <var>init</var>.
</p>
<p>The optional fourth argument <var>ode_opt</var> specifies non-default options to
the ODE solver.  It is a structure generated by <code>odeset</code>.
</p>
<p>The function typically returns two outputs.  Variable <var>t</var> is a
column vector and contains the times where the solution was found.  The
output <var>y</var> is a matrix in which each column refers to a different
unknown of the problem and each row corresponds to a time in <var>t</var>.
</p>
<p>The output can also be returned as a structure <var>solution</var> which has a
field <var>x</var> containing a row vector of times where the solution was
evaluated and a field <var>y</var> containing the solution matrix such that each
column corresponds to a time in <var>x</var>.  Use
<code>fieldnames&nbsp;(<var>solution</var>)</code><!-- /@w --> to see the other fields and
additional information returned.
</p>
<p>If no output arguments are requested, and no <code>&quot;OutputFcn&quot;</code> is
specified in <var>ode_opt</var>, then the <code>&quot;OutputFcn&quot;</code> is set to
<code>odeplot</code> and the results of the solver are plotted immediately.
</p>
<p>If using the <code>&quot;Events&quot;</code> option then three additional outputs may be
returned.  <var>te</var> holds the time when an Event function returned a zero.
<var>ye</var> holds the value of the solution at time <var>te</var>.  <var>ie</var>
contains an index indicating which Event function was triggered in the case
of multiple Event functions.
</p>
<p>Example: Solve the Van der Pol equation
</p>
<div class="example">
<pre class="example">fvdp = @(<var>t</var>,<var>y</var>) [<var>y</var>(2); (1 - <var>y</var>(1)^2) * <var>y</var>(2) - <var>y</var>(1)];
[<var>t</var>,<var>y</var>] = ode45 (fvdp, [0, 20], [2, 0]);
</pre></div>

<p><strong>See also:</strong> <a href="#XREFodeset">odeset</a>, <a href="#XREFodeget">odeget</a>, <a href="#XREFode23">ode23</a>, <a href="#XREFode15s">ode15s</a>.
</p></dd></dl>


<span id="XREFode23"></span><dl>
<dt id="index-ode23">: <em>[<var>t</var>, <var>y</var>] =</em> <strong>ode23</strong> <em>(<var>fun</var>, <var>trange</var>, <var>init</var>)</em></dt>
<dt id="index-ode23-1">: <em>[<var>t</var>, <var>y</var>] =</em> <strong>ode23</strong> <em>(<var>fun</var>, <var>trange</var>, <var>init</var>, <var>ode_opt</var>)</em></dt>
<dt id="index-ode23-2">: <em>[<var>t</var>, <var>y</var>, <var>te</var>, <var>ye</var>, <var>ie</var>] =</em> <strong>ode23</strong> <em>(&hellip;)</em></dt>
<dt id="index-ode23-3">: <em><var>solution</var> =</em> <strong>ode23</strong> <em>(&hellip;)</em></dt>
<dt id="index-ode23-4">: <em></em> <strong>ode23</strong> <em>(&hellip;)</em></dt>
<dd>
<p>Solve a set of non-stiff Ordinary Differential Equations (non-stiff ODEs)
with the well known explicit Bogacki-Shampine method of order 3.
</p>
<p><var>fun</var> is a function handle, inline function, or string containing the
name of the function that defines the ODE: <code>y' = f(t,y)</code>.  The function
must accept two inputs where the first is time <var>t</var> and the second is a
column vector of unknowns <var>y</var>.
</p>
<p><var>trange</var> specifies the time interval over which the ODE will be
evaluated.  Typically, it is a two-element vector specifying the initial and
final times (<code>[tinit, tfinal]</code>).  If there are more than two elements
then the solution will also be evaluated at these intermediate time
instances.
</p>
<p>By default, <code>ode23</code> uses an adaptive timestep with the
<code>integrate_adaptive</code> algorithm.  The tolerance for the timestep
computation may be changed by using the options <code>&quot;RelTol&quot;</code> and
<code>&quot;AbsTol&quot;</code>.
</p>
<p><var>init</var> contains the initial value for the unknowns.  If it is a row
vector then the solution <var>y</var> will be a matrix in which each column is
the solution for the corresponding initial value in <var>init</var>.
</p>
<p>The optional fourth argument <var>ode_opt</var> specifies non-default options to
the ODE solver.  It is a structure generated by <code>odeset</code>.
</p>
<p>The function typically returns two outputs.  Variable <var>t</var> is a
column vector and contains the times where the solution was found.  The
output <var>y</var> is a matrix in which each column refers to a different
unknown of the problem and each row corresponds to a time in <var>t</var>.
</p>
<p>The output can also be returned as a structure <var>solution</var> which has a
field <var>x</var> containing a row vector of times where the solution was
evaluated and a field <var>y</var> containing the solution matrix such that each
column corresponds to a time in <var>x</var>.  Use
<code>fieldnames&nbsp;(<var>solution</var>)</code><!-- /@w --> to see the other fields and
additional information returned.
</p>
<p>If no output arguments are requested, and no <code>&quot;OutputFcn&quot;</code> is
specified in <var>ode_opt</var>, then the <code>&quot;OutputFcn&quot;</code> is set to
<code>odeplot</code> and the results of the solver are plotted immediately.
</p>
<p>If using the <code>&quot;Events&quot;</code> option then three additional outputs may be
returned.  <var>te</var> holds the time when an Event function returned a zero.
<var>ye</var> holds the value of the solution at time <var>te</var>.  <var>ie</var>
contains an index indicating which Event function was triggered in the case
of multiple Event functions.
</p>
<p>Example: Solve the Van der Pol equation
</p>
<div class="example">
<pre class="example">fvdp = @(<var>t</var>,<var>y</var>) [<var>y</var>(2); (1 - <var>y</var>(1)^2) * <var>y</var>(2) - <var>y</var>(1)];
[<var>t</var>,<var>y</var>] = ode23 (fvdp, [0, 20], [2, 0]);
</pre></div>

<p>Reference: For the definition of this method see
<a href="https://en.wikipedia.org/wiki/List_of_Runge%E2%80%93Kutta_methods">https://en.wikipedia.org/wiki/List_of_Runge%E2%80%93Kutta_methods</a>.
</p>
<p><strong>See also:</strong> <a href="#XREFodeset">odeset</a>, <a href="#XREFodeget">odeget</a>, <a href="#XREFode45">ode45</a>, <a href="#XREFode15s">ode15s</a>.
</p></dd></dl>


<span id="XREFode23s"></span><dl>
<dt id="index-ode23s">: <em>[<var>t</var>, <var>y</var>] =</em> <strong>ode23s</strong> <em>(<var>fun</var>, <var>trange</var>, <var>init</var>)</em></dt>
<dt id="index-ode23s-1">: <em>[<var>t</var>, <var>y</var>] =</em> <strong>ode23s</strong> <em>(<var>fun</var>, <var>trange</var>, <var>init</var>, <var>ode_opt</var>)</em></dt>
<dt id="index-ode23s-2">: <em>[<var>t</var>, <var>y</var>] =</em> <strong>ode23s</strong> <em>(&hellip;, <var>par1</var>, <var>par2</var>, &hellip;)</em></dt>
<dt id="index-ode23s-3">: <em>[<var>t</var>, <var>y</var>, <var>te</var>, <var>ye</var>, <var>ie</var>] =</em> <strong>ode23s</strong> <em>(&hellip;)</em></dt>
<dt id="index-ode23s-4">: <em><var>solution</var> =</em> <strong>ode23s</strong> <em>(&hellip;)</em></dt>
<dd>
<p>Solve a set of stiff Ordinary Differential Equations (stiff ODEs) with a
Rosenbrock method of order (2,3).
</p>
<p><var>fun</var> is a function handle, inline function, or string containing the
name of the function that defines the ODE: <code>M y' = f(t,y)</code>.  The
function must accept two inputs where the first is time <var>t</var> and the
second is a column vector of unknowns <var>y</var>.  <var>M</var> is a constant mass
matrix, non-singular and possibly sparse.  Set the field <code>&quot;Mass&quot;</code> in
<var>odeopts</var> using <var>odeset</var> to specify a mass matrix.
</p>
<p><var>trange</var> specifies the time interval over which the ODE will be
evaluated.  Typically, it is a two-element vector specifying the initial
and final times (<code>[tinit, tfinal]</code>).  If there are more than two
elements then the solution will also be evaluated at these intermediate
time instances using an interpolation procedure of the same order as the
one of the solver.
</p>
<p>By default, <code>ode23s</code> uses an adaptive timestep with the
<code>integrate_adaptive</code> algorithm.  The tolerance for the timestep
computation may be changed by using the options <code>&quot;RelTol&quot;</code> and
<code>&quot;AbsTol&quot;</code>.
</p>
<p><var>init</var> contains the initial value for the unknowns.  If it is a row
vector then the solution <var>y</var> will be a matrix in which each column is
the solution for the corresponding initial value in <var>init</var>.
</p>
<p>The optional fourth argument <var>ode_opt</var> specifies non-default options to
the ODE solver.  It is a structure generated by <code>odeset</code>.
<code>ode23s</code> will ignore the following options: <code>&quot;BDF&quot;</code>,
<code>&quot;InitialSlope&quot;</code>, <code>&quot;MassSingular&quot;</code>, <code>&quot;MStateDependence&quot;</code>,
<code>&quot;MvPattern&quot;</code>, <code>&quot;MaxOrder&quot;</code>, <code>&quot;Non-negative&quot;</code>.
</p>
<p>The function typically returns two outputs.  Variable <var>t</var> is a
column vector and contains the times where the solution was found.  The
output <var>y</var> is a matrix in which each column refers to a different
unknown of the problem and each row corresponds to a time in <var>t</var>.  If
<var>trange</var> specifies intermediate time steps, only those will be returned.
</p>
<p>The output can also be returned as a structure <var>solution</var> which has a
field <var>x</var> containing a row vector of times where the solution was
evaluated and a field <var>y</var> containing the solution matrix such that each
column corresponds to a time in <var>x</var>.  Use
<code>fieldnames&nbsp;(<var>solution</var>)</code><!-- /@w --> to see the other fields and
additional information returned.
</p>
<p>If using the <code>&quot;Events&quot;</code> option then three additional outputs may be
returned.  <var>te</var> holds the time when an Event function returned a zero.
<var>ye</var> holds the value of the solution at time <var>te</var>.  <var>ie</var>
contains an index indicating which Event function was triggered in the case
of multiple Event functions.
</p>
<p>Example: Solve the stiff Van der Pol equation
</p>
<div class="example">
<pre class="example">f = @(<var>t</var>,<var>y</var>) [<var>y</var>(2); 1000*(1 - <var>y</var>(1)^2) * <var>y</var>(2) - <var>y</var>(1)];
opt = odeset ('Mass', [1 0; 0 1], 'MaxStep', 1e-1);
[vt, vy] = ode23s (f, [0 2000], [2 0], opt);
</pre></div>

<p><strong>See also:</strong> <a href="#XREFodeset">odeset</a>, <a href="Differential_002dAlgebraic-Equations.html#XREFdaspk">daspk</a>, <a href="Differential_002dAlgebraic-Equations.html#XREFdassl">dassl</a>.
</p></dd></dl>


<span id="XREFode15s"></span><dl>
<dt id="index-ode15s">: <em>[<var>t</var>, <var>y</var>] =</em> <strong>ode15s</strong> <em>(<var>fun</var>, <var>trange</var>, <var>y0</var>)</em></dt>
<dt id="index-ode15s-1">: <em>[<var>t</var>, <var>y</var>] =</em> <strong>ode15s</strong> <em>(<var>fun</var>, <var>trange</var>, <var>y0</var>, <var>ode_opt</var>)</em></dt>
<dt id="index-ode15s-2">: <em>[<var>t</var>, <var>y</var>, <var>te</var>, <var>ye</var>, <var>ie</var>] =</em> <strong>ode15s</strong> <em>(&hellip;)</em></dt>
<dt id="index-ode15s-3">: <em><var>solution</var> =</em> <strong>ode15s</strong> <em>(&hellip;)</em></dt>
<dt id="index-ode15s-4">: <em></em> <strong>ode15s</strong> <em>(&hellip;)</em></dt>
<dd><p>Solve a set of stiff Ordinary Differential Equations (ODEs) or stiff
semi-explicit index 1 Differential Algebraic Equations (DAEs).
</p>
<p><code>ode15s</code> uses a variable step, variable order BDF (Backward
Differentiation Formula) method that ranges from order 1 to 5.
</p>
<p><var>fun</var> is a function handle, inline function, or string containing the
name of the function that defines the ODE: <code>y' = f(t,y)</code>.  The function
must accept two inputs where the first is time <var>t</var> and the second is a
column vector of unknowns <var>y</var>.
</p>
<p><var>trange</var> specifies the time interval over which the ODE will be
evaluated.  Typically, it is a two-element vector specifying the initial and
final times (<code>[tinit, tfinal]</code>).  If there are more than two elements
then the solution will also be evaluated at these intermediate time
instances.
</p>
<p><var>init</var> contains the initial value for the unknowns.  If it is a row
vector then the solution <var>y</var> will be a matrix in which each column is
the solution for the corresponding initial value in <var>init</var>.
</p>
<p>The optional fourth argument <var>ode_opt</var> specifies non-default options to
the ODE solver.  It is a structure generated by <code>odeset</code>.
</p>
<p>The function typically returns two outputs.  Variable <var>t</var> is a
column vector and contains the times where the solution was found.  The
output <var>y</var> is a matrix in which each column refers to a different
unknown of the problem and each row corresponds to a time in <var>t</var>.
</p>
<p>The output can also be returned as a structure <var>solution</var> which has a
field <var>x</var> containing a row vector of times where the solution was
evaluated and a field <var>y</var> containing the solution matrix such that each
column corresponds to a time in <var>x</var>.  Use
<code>fieldnames&nbsp;(<var>solution</var>)</code><!-- /@w --> to see the other fields and
additional information returned.
</p>
<p>If no output arguments are requested, and no <code>&quot;OutputFcn&quot;</code> is
specified in <var>ode_opt</var>, then the <code>&quot;OutputFcn&quot;</code> is set to
<code>odeplot</code> and the results of the solver are plotted immediately.
</p>
<p>If using the <code>&quot;Events&quot;</code> option then three additional outputs may be
returned.  <var>te</var> holds the time when an Event function returned a zero.
<var>ye</var> holds the value of the solution at time <var>te</var>.  <var>ie</var>
contains an index indicating which Event function was triggered in the case
of multiple Event functions.
</p>
<p>Example: Solve Robertson&rsquo;s equations:
</p>
<div class="example">
<pre class="example">function r = robertson_dae (<var>t</var>, <var>y</var>)
  r = [ -0.04*<var>y</var>(1) + 1e4*<var>y</var>(2)*<var>y</var>(3)
         0.04*<var>y</var>(1) - 1e4*<var>y</var>(2)*<var>y</var>(3) - 3e7*<var>y</var>(2)^2
<var>y</var>(1) + <var>y</var>(2) + <var>y</var>(3) - 1 ];
endfunction
opt = odeset (&quot;Mass&quot;, [1 0 0; 0 1 0; 0 0 0], &quot;MStateDependence&quot;, &quot;none&quot;);
[<var>t</var>,<var>y</var>] = ode15s (@robertson_dae, [0, 1e3], [1; 0; 0], opt);
</pre></div>

<p><strong>See also:</strong> <a href="#XREFdecic">decic</a>, <a href="#XREFodeset">odeset</a>, <a href="#XREFodeget">odeget</a>, <a href="#XREFode23">ode23</a>, <a href="#XREFode45">ode45</a>.
</p></dd></dl>


<span id="XREFode15i"></span><dl>
<dt id="index-ode15i">: <em>[<var>t</var>, <var>y</var>] =</em> <strong>ode15i</strong> <em>(<var>fun</var>, <var>trange</var>, <var>y0</var>, <var>yp0</var>)</em></dt>
<dt id="index-ode15i-1">: <em>[<var>t</var>, <var>y</var>] =</em> <strong>ode15i</strong> <em>(<var>fun</var>, <var>trange</var>, <var>y0</var>, <var>yp0</var>, <var>ode_opt</var>)</em></dt>
<dt id="index-ode15i-2">: <em>[<var>t</var>, <var>y</var>, <var>te</var>, <var>ye</var>, <var>ie</var>] =</em> <strong>ode15i</strong> <em>(&hellip;)</em></dt>
<dt id="index-ode15i-3">: <em><var>solution</var> =</em> <strong>ode15i</strong> <em>(&hellip;)</em></dt>
<dt id="index-ode15i-4">: <em></em> <strong>ode15i</strong> <em>(&hellip;)</em></dt>
<dd><p>Solve a set of fully-implicit Ordinary Differential Equations (ODEs) or
index 1 Differential Algebraic Equations (DAEs).
</p>
<p><code>ode15i</code> uses a variable step, variable order BDF (Backward
Differentiation Formula) method that ranges from order 1 to 5.
</p>
<p><var>fun</var> is a function handle, inline function, or string containing the
name of the function that defines the ODE: <code>0 = f(t,y,yp)</code>.  The
function must accept three inputs where the first is time <var>t</var>, the
second is the function value <var>y</var> (a column vector), and the third
is the derivative value <var>yp</var> (a column vector).
</p>
<p><var>trange</var> specifies the time interval over which the ODE will be
evaluated.  Typically, it is a two-element vector specifying the initial and
final times (<code>[tinit, tfinal]</code>).  If there are more than two elements
then the solution will also be evaluated at these intermediate time
instances.
</p>
<p><var>y0</var> and <var>yp0</var> contain the initial values for the unknowns <var>y</var>
and <var>yp</var>.  If they are row vectors then the solution <var>y</var> will be a
matrix in which each column is the solution for the corresponding initial
value in <var>y0</var> and <var>yp0</var>.
</p>
<p><var>y0</var> and <var>yp0</var> must be consistent initial conditions, meaning that
<code>f(t,y0,yp0) = 0</code> is satisfied.  The function <code>decic</code> may be used
to compute consistent initial conditions given initial guesses.
</p>
<p>The optional fifth argument <var>ode_opt</var> specifies non-default options to
the ODE solver.  It is a structure generated by <code>odeset</code>.
</p>
<p>The function typically returns two outputs.  Variable <var>t</var> is a
column vector and contains the times where the solution was found.  The
output <var>y</var> is a matrix in which each column refers to a different
unknown of the problem and each row corresponds to a time in <var>t</var>.
</p>
<p>The output can also be returned as a structure <var>solution</var> which has a
field <var>x</var> containing a row vector of times where the solution was
evaluated and a field <var>y</var> containing the solution matrix such that each
column corresponds to a time in <var>x</var>.  Use
<code>fieldnames&nbsp;(<var>solution</var>)</code><!-- /@w --> to see the other fields and
additional information returned.
</p>
<p>If no output arguments are requested, and no <code>&quot;OutputFcn&quot;</code> is
specified in <var>ode_opt</var>, then the <code>&quot;OutputFcn&quot;</code> is set to
<code>odeplot</code> and the results of the solver are plotted immediately.
</p>
<p>If using the <code>&quot;Events&quot;</code> option then three additional outputs may be
returned.  <var>te</var> holds the time when an Event function returned a zero.
<var>ye</var> holds the value of the solution at time <var>te</var>.  <var>ie</var>
contains an index indicating which Event function was triggered in the case
of multiple Event functions.
</p>
<p>Example: Solve Robertson&rsquo;s equations:
</p>
<div class="example">
<pre class="example">function r = robertson_dae (<var>t</var>, <var>y</var>, <var>yp</var>)
  r = [ -(<var>yp</var>(1) + 0.04*<var>y</var>(1) - 1e4*<var>y</var>(2)*<var>y</var>(3))
        -(<var>yp</var>(2) - 0.04*<var>y</var>(1) + 1e4*<var>y</var>(2)*<var>y</var>(3) + 3e7*<var>y</var>(2)^2)
<var>y</var>(1) + <var>y</var>(2) + <var>y</var>(3) - 1 ];
endfunction
[<var>t</var>,<var>y</var>] = ode15i (@robertson_dae, [0, 1e3], [1; 0; 0], [-1e-4; 1e-4; 0]);
</pre></div>

<p><strong>See also:</strong> <a href="#XREFdecic">decic</a>, <a href="#XREFodeset">odeset</a>, <a href="#XREFodeget">odeget</a>.
</p></dd></dl>


<span id="XREFdecic"></span><dl>
<dt id="index-decic">: <em>[<var>y0_new</var>, <var>yp0_new</var>] =</em> <strong>decic</strong> <em>(<var>fun</var>, <var>t0</var>, <var>y0</var>, <var>fixed_y0</var>, <var>yp0</var>, <var>fixed_yp0</var>)</em></dt>
<dt id="index-decic-1">: <em>[<var>y0_new</var>, <var>yp0_new</var>] =</em> <strong>decic</strong> <em>(<var>fun</var>, <var>t0</var>, <var>y0</var>, <var>fixed_y0</var>, <var>yp0</var>, <var>fixed_yp0</var>, <var>options</var>)</em></dt>
<dt id="index-decic-2">: <em>[<var>y0_new</var>, <var>yp0_new</var>, <var>resnorm</var>] =</em> <strong>decic</strong> <em>(&hellip;)</em></dt>
<dd>
<p>Compute consistent implicit ODE initial conditions <var>y0_new</var> and
<var>yp0_new</var> given initial guesses <var>y0</var> and <var>yp0</var>.
</p>
<p>A maximum of <code>length (<var>y0</var>)</code> components between <var>fixed_y0</var> and
<var>fixed_yp0</var> may be chosen as fixed values.
</p>
<p><var>fun</var> is a function handle.  The function must accept three inputs where
the first is time <var>t</var>, the second is a column vector of unknowns
<var>y</var>, and the third is a column vector of unknowns <var>yp</var>.
</p>
<p><var>t0</var> is the initial time such that
<code><var>fun</var>(<var>t0</var>, <var>y0_new</var>, <var>yp0_new</var>) = 0</code>, specified as a
scalar.
</p>
<p><var>y0</var> is a vector used as the initial guess for <var>y</var>.
</p>
<p><var>fixed_y0</var> is a vector which specifies the components of <var>y0</var> to
hold fixed.  Choose a maximum of <code>length (<var>y0</var>)</code> components between
<var>fixed_y0</var> and <var>fixed_yp0</var> as fixed values.
Set <var>fixed_y0</var>(i) component to 1 if you want to fix the value of
<var>y0</var>(i).
Set <var>fixed_y0</var>(i) component to 0 if you want to allow the value of
<var>y0</var>(i) to change.
</p>
<p><var>yp0</var> is a vector used as the initial guess for <var>yp</var>.
</p>
<p><var>fixed_yp0</var> is a vector which specifies the components of <var>yp0</var> to
hold fixed.  Choose a maximum of <code>length (<var>yp0</var>)</code> components
between <var>fixed_y0</var> and <var>fixed_yp0</var> as fixed values.
Set <var>fixed_yp0</var>(i) component to 1 if you want to fix the value of
<var>yp0</var>(i).
Set <var>fixed_yp0</var>(i) component to 0 if you want to allow the value of
<var>yp0</var>(i) to change.
</p>
<p>The optional seventh argument <var>options</var> is a structure array.  Use
<code>odeset</code> to generate this structure.  The relevant options are
<code>RelTol</code> and <code>AbsTol</code> which specify the error thresholds used to
compute the initial conditions.
</p>
<p>The function typically returns two outputs.  Variable <var>y0_new</var> is a
column vector and contains the consistent initial value of <var>y</var>.  The
output <var>yp0_new</var> is a column vector and contains the consistent initial
value of <var>yp</var>.
</p>
<p>The optional third output <var>resnorm</var> is the norm of the vector of
residuals.  If <var>resnorm</var> is small, <code>decic</code> has successfully
computed the initial conditions.  If the value of <var>resnorm</var> is large,
use <code>RelTol</code> and <code>AbsTol</code> to adjust it.
</p>
<p>Example: Compute initial conditions for Robertson&rsquo;s equations:
</p>
<div class="example">
<pre class="example">function r = robertson_dae (<var>t</var>, <var>y</var>, <var>yp</var>)
  r = [ -(<var>yp</var>(1) + 0.04*<var>y</var>(1) - 1e4*<var>y</var>(2)*<var>y</var>(3))
        -(<var>yp</var>(2) - 0.04*<var>y</var>(1) + 1e4*<var>y</var>(2)*<var>y</var>(3) + 3e7*<var>y</var>(2)^2)
<var>y</var>(1) + <var>y</var>(2) + <var>y</var>(3) - 1 ];
endfunction
</pre><pre class="example">[<var>y0_new</var>,<var>yp0_new</var>] = decic (@robertson_dae, 0, [1; 0; 0], [1; 1; 0],
[-1e-4; 1; 0], [0; 0; 0]);
</pre></div>

<p><strong>See also:</strong> <a href="#XREFode15i">ode15i</a>, <a href="#XREFodeset">odeset</a>.
</p></dd></dl>


<span id="XREFodeset"></span><dl>
<dt id="index-odeset">: <em><var>odestruct</var> =</em> <strong>odeset</strong> <em>()</em></dt>
<dt id="index-odeset-1">: <em><var>odestruct</var> =</em> <strong>odeset</strong> <em>(<var>&quot;field1&quot;</var>, <var>value1</var>, <var>&quot;field2&quot;</var>, <var>value2</var>, &hellip;)</em></dt>
<dt id="index-odeset-2">: <em><var>odestruct</var> =</em> <strong>odeset</strong> <em>(<var>oldstruct</var>, <var>&quot;field1&quot;</var>, <var>value1</var>, <var>&quot;field2&quot;</var>, <var>value2</var>, &hellip;)</em></dt>
<dt id="index-odeset-3">: <em><var>odestruct</var> =</em> <strong>odeset</strong> <em>(<var>oldstruct</var>, <var>newstruct</var>)</em></dt>
<dt id="index-odeset-4">: <em></em> <strong>odeset</strong> <em>()</em></dt>
<dd>
<p>Create or modify an ODE options structure.
</p>
<p>When called with no input argument and one output argument, return a new ODE
options structure that contains all possible fields initialized to their
default values.  If no output argument is requested, display a list of
the common ODE solver options along with their default value.
</p>
<p>If called with name-value input argument pairs <var>&quot;field1&quot;</var>,
<var>&quot;value1&quot;</var>, <var>&quot;field2&quot;</var>, <var>&quot;value2&quot;</var>, &hellip; return a new
ODE options structure with all the most common option fields
initialized, <strong>and</strong> set the values of the fields <var>&quot;field1&quot;</var>,
<var>&quot;field2&quot;</var>, &hellip; to the values <var>value1</var>, <var>value2</var>,
&hellip;.
</p>
<p>If called with an input structure <var>oldstruct</var> then overwrite the
values of the options <var>&quot;field1&quot;</var>, <var>&quot;field2&quot;</var>, &hellip; with
new values <var>value1</var>, <var>value2</var>, &hellip; and return the
modified structure.
</p>
<p>When called with two input ODE options structures <var>oldstruct</var> and
<var>newstruct</var> overwrite all values from the structure
<var>oldstruct</var> with new values from the structure <var>newstruct</var>.
Empty values in <var>newstruct</var> will not overwrite values in
<var>oldstruct</var>.
</p>
<p>The most commonly used ODE options, which are always assigned a value
by <code>odeset</code>, are the following:
</p>
<dl compact="compact">
<dt><code>AbsTol</code>: positive scalar | vector, def. <code>1e-6</code></dt>
<dd><p>Absolute error tolerance.
</p>
</dd>
<dt><code>BDF</code>: {<code>&quot;off&quot;</code>} | <code>&quot;on&quot;</code></dt>
<dd><p>Use BDF formulas in implicit multistep methods.
<em>Note</em>: This option is not yet implemented.
</p>
</dd>
<dt><code>Events</code>: function_handle</dt>
<dd><p>Event function.  An event function must have the form
<code>[value, isterminal, direction] = my_events_f (t, y)</code>
</p>
</dd>
<dt><code>InitialSlope</code>: vector</dt>
<dd><p>Consistent initial slope vector for DAE solvers.
</p>
</dd>
<dt><code>InitialStep</code>: positive scalar</dt>
<dd><p>Initial time step size.
</p>
</dd>
<dt><code>Jacobian</code>: matrix | function_handle</dt>
<dd><p>Jacobian matrix, specified as a constant matrix or a function of
time and state.
</p>
</dd>
<dt><code>JConstant</code>: {<code>&quot;off&quot;</code>} | <code>&quot;on&quot;</code></dt>
<dd><p>Specify whether the Jacobian is a constant matrix or depends on the
state.
</p>
</dd>
<dt><code>JPattern</code>: sparse matrix</dt>
<dd><p>If the Jacobian matrix is sparse and non-constant but maintains a
constant sparsity pattern, specify the sparsity pattern.
</p>
</dd>
<dt><code>Mass</code>: matrix | function_handle</dt>
<dd><p>Mass matrix, specified as a constant matrix or a function of
time and state.
</p>
</dd>
<dt><code>MassSingular</code>: {<code>&quot;maybe&quot;</code>} | <code>&quot;yes&quot;</code> | <code>&quot;on&quot;</code></dt>
<dd><p>Specify whether the mass matrix is singular.
</p>
</dd>
<dt><code>MaxOrder</code>: {<code>5</code>} | <code>4</code> | <code>3</code> | <code>2</code> | <code>1</code></dt>
<dd><p>Maximum order of formula.
</p>
</dd>
<dt><code>MaxStep</code>: positive scalar</dt>
<dd><p>Maximum time step value.
</p>
</dd>
<dt><code>MStateDependence</code>: {<code>&quot;weak&quot;</code>} | <code>&quot;none&quot;</code> | <code>&quot;strong&quot;</code></dt>
<dd><p>Specify whether the mass matrix depends on the state or only on time.
</p>
</dd>
<dt><code>MvPattern</code>: sparse matrix</dt>
<dd><p>If the mass matrix is sparse and non-constant but maintains a
constant sparsity pattern, specify the sparsity pattern.
<em>Note</em>: This option is not yet implemented.
</p>
</dd>
<dt><code>NonNegative</code>: scalar | vector</dt>
<dd><p>Specify elements of the state vector that are expected to remain
non-negative during the simulation.
</p>
</dd>
<dt><code>NormControl</code>: {<code>&quot;off&quot;</code>} | <code>&quot;on&quot;</code></dt>
<dd><p>Control error relative to the 2-norm of the solution, rather than its
absolute value.
</p>
</dd>
<dt><code>OutputFcn</code>: function_handle</dt>
<dd><p>Function to monitor the state during the simulation.  For the form of
the function to use see <code>odeplot</code>.
</p>
</dd>
<dt><code>OutputSel</code>: scalar | vector</dt>
<dd><p>Indices of elements of the state vector to be passed to the output
monitoring function.
</p>
</dd>
<dt><code>Refine</code>: positive scalar</dt>
<dd><p>Specify whether output should be returned only at the end of each
time step or also at intermediate time instances.  The value should be
a scalar indicating the number of equally spaced time points to use
within each timestep at which to return output.
<em>Note</em>: This option is not yet implemented.
</p>
</dd>
<dt><code>RelTol</code>: positive scalar</dt>
<dd><p>Relative error tolerance.
</p>
</dd>
<dt><code>Stats</code>: {<code>&quot;off&quot;</code>} | <code>&quot;on&quot;</code></dt>
<dd><p>Print solver statistics after simulation.
</p>
</dd>
<dt><code>Vectorized</code>: {<code>&quot;off&quot;</code>} | <code>&quot;on&quot;</code></dt>
<dd><p>Specify whether <code>odefun</code> can be passed multiple values of the
state at once.
</p>
</dd>
</dl>

<p>Field names that are not in the above list are also accepted and
added to the result structure.
</p>

<p><strong>See also:</strong> <a href="#XREFodeget">odeget</a>.
</p></dd></dl>


<span id="XREFodeget"></span><dl>
<dt id="index-odeget">: <em><var>val</var> =</em> <strong>odeget</strong> <em>(<var>ode_opt</var>, <var>field</var>)</em></dt>
<dt id="index-odeget-1">: <em><var>val</var> =</em> <strong>odeget</strong> <em>(<var>ode_opt</var>, <var>field</var>, <var>default</var>)</em></dt>
<dd>
<p>Query the value of the property <var>field</var> in the ODE options structure
<var>ode_opt</var>.
</p>
<p>If called with two input arguments and the first input argument
<var>ode_opt</var> is an ODE option structure and the second input argument
<var>field</var> is a string specifying an option name, then return the option
value <var>val</var> corresponding to <var>field</var> from <var>ode_opt</var>.
</p>
<p>If called with an optional third input argument, and <var>field</var> is
not set in the structure <var>ode_opt</var>, then return the default value
<var>default</var> instead.
</p>
<p><strong>See also:</strong> <a href="#XREFodeset">odeset</a>.
</p></dd></dl>


<span id="XREFodeplot"></span><dl>
<dt id="index-odeplot">: <em><var>stop_solve</var> =</em> <strong>odeplot</strong> <em>(<var>t</var>, <var>y</var>, <var>flag</var>)</em></dt>
<dd>
<p>Open a new figure window and plot the solution of an ode problem at each
time step during the integration.
</p>
<p>The types and values of the input parameters <var>t</var> and <var>y</var> depend on
the input <var>flag</var> that is of type string.  Valid values of <var>flag</var>
are:
</p>
<dl compact="compact">
<dt><samp><code>&quot;init&quot;</code></samp></dt>
<dd><p>The input <var>t</var> must be a column vector of length 2 with the first and
last time step (<code>[<var>tfirst</var> <var>tlast</var>]</code>.  The input <var>y</var>
contains the initial conditions for the ode problem (<var>y0</var>).
</p>
</dd>
<dt><samp><code>&quot;&quot;</code></samp></dt>
<dd><p>The input <var>t</var> must be a scalar double specifying the time for which
the solution in input <var>y</var> was calculated.
</p>
</dd>
<dt><samp><code>&quot;done&quot;</code></samp></dt>
<dd><p>The inputs should be empty, but are ignored if they are present.
</p></dd>
</dl>

<p><code>odeplot</code> always returns false, i.e., don&rsquo;t stop the ode solver.
</p>
<p>Example: solve an anonymous implementation of the
<code>&quot;Van der Pol&quot;</code> equation and display the results while
solving.
</p>
<div class="example">
<pre class="example">fvdp = @(t,y) [y(2); (1 - y(1)^2) * y(2) - y(1)];

opt = odeset (&quot;OutputFcn&quot;, @odeplot, &quot;RelTol&quot;, 1e-6);
sol = ode45 (fvdp, [0 20], [2 0], opt);
</pre></div>

<p>Background Information:
This function is called by an ode solver function if it was specified in
the <code>&quot;OutputFcn&quot;</code> property of an options structure created with
<code>odeset</code>.  The ode solver will initially call the function with the
syntax <code>odeplot ([<var>tfirst</var>, <var>tlast</var>], <var>y0</var>, &quot;init&quot;)</code>.  The
function initializes internal variables, creates a new figure window, and
sets the x limits of the plot.  Subsequently, at each time step during the
integration the ode solver calls <code>odeplot (<var>t</var>, <var>y</var>, [])</code>.
At the end of the solution the ode solver calls
<code>odeplot ([], [], &quot;done&quot;)</code> so that odeplot can perform any clean-up
actions required.
</p>
<p><strong>See also:</strong> <a href="#XREFodeset">odeset</a>, <a href="#XREFodeget">odeget</a>, <a href="#XREFode23">ode23</a>, <a href="#XREFode45">ode45</a>.
</p></dd></dl>


<hr>
<div class="header">
<p>
Up: <a href="Ordinary-Differential-Equations.html" accesskey="u" rel="up">Ordinary Differential Equations</a> &nbsp; [<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>