Spaces:
Sleeping

File size: 13,401 Bytes
39e01c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( https://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) Scilab Enterprises - 2012 - Paul Bignier
 *
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg"  xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en_US" xml:id="ImpRK">
    <refnamediv>
        <refname>Implicit Runge-Kutta 4(5)</refname>
        <refpurpose>
            Numerical solver providing an efficient and stable implicit method to solve Ordinary Differential Equations (ODEs) Initial Value Problems.
        </refpurpose>
    </refnamediv>
    <refsection>
        <title>Description</title>
        <para>
            <emphasis>Runge-Kutta</emphasis> is a numerical solver providing an efficient and stable fixed-size step method to solve Initial Value Problems of the form:
        </para>
        <para>
            <latex>
                \begin{eqnarray}
                \dot{y} = f(t,y), \hspace{3 mm} y(t_0) = y_0, \hspace{3 mm} y \in R^N
                \end{eqnarray}
            </latex>
        </para>
        <para>
            <emphasis>CVode</emphasis> and <emphasis>IDA</emphasis> use variable-size steps for the integration.
        </para>
        <para>
            A drawback of that is the unpredictable computation time. With <emphasis>Runge-Kutta</emphasis>, we do not adapt to the complexity of the problem, but we guarantee a stable computation time.
        </para>
        <para>
            This method being implicit, it can be used on stiff problems.
        </para>
        <para>
            It is an enhancement of the backward Euler method, which approximates
            <emphasis>
                y<subscript>n+1</subscript>
            </emphasis>
            by computing
            <emphasis>
                f(t<subscript>n</subscript>+h, y<subscript>n+1</subscript>)
            </emphasis>
            and truncating the Taylor expansion.
        </para>
        <para>
            The implemented scheme is inspired from the "Low-Dispersion Low-Dissipation Implicit Runge-Kutta Scheme" (see bottom for link).
        </para>
        <para>
            By convention, to use fixed-size steps, the program first computes a fitting <emphasis>h</emphasis> that approaches the simulation parameter <link linkend="Simulatemenu_Menu_entries">max step size</link>.
        </para>
        <para>
            An important difference of <emphasis>implicit Runge-Kutta</emphasis> with the previous methods is that it computes up to the fourth derivative of <emphasis>y</emphasis>, while the others only use linear combinations of <emphasis>y</emphasis> and <emphasis>y'</emphasis>.
        </para>
        <para>
            Here, the next value is determined by the present value
            <emphasis>
                y<subscript>n</subscript>
            </emphasis>
            plus the weighted average of three increments, where each increment is the product of the size of the interval, <emphasis>h</emphasis>, and an estimated slope specified by the function <emphasis>f(t,y)</emphasis>. They are distributed approximately equally on the interval.
            <itemizedlist>
                <listitem>
                    <emphasis>k1</emphasis> is the increment based on the slope near the quarter of the interval, using
                    <emphasis>
                        y<subscript>n</subscript>+ a11*h*k1
                    </emphasis>
                    ,
                </listitem>
                <listitem>
                    <emphasis>k2</emphasis> is the increment based on the slope near the midpoint of the interval, using
                    <emphasis>
                        y<subscript>n</subscript> + a21*h*k1 + a22*h*k2
                    </emphasis>
                    ,
                </listitem>
                <listitem>
                    <emphasis>k3</emphasis> is the increment based on the slope near the third quarter of the interval, using
                    <emphasis>
                        y<subscript>n</subscript> + a31*h*k1 + a32*h*k2 + a33*h*k3
                    </emphasis>
                    .
                </listitem>
            </itemizedlist>
        </para>
        <para>
            We see that the computation of <emphasis>ki</emphasis> requires <emphasis>ki</emphasis>, thus necessitating the use of a nonlinear solver (here, fixed-point iterations).
        </para>
        <para>
            First, we set
            <emphasis>
                k0 = h * f(t<subscript>n</subscript>, y<subscript>n</subscript>)
            </emphasis>
            as first guess for all the <emphasis>ki</emphasis>, to get updated <emphasis>ki</emphasis> and a first value for
            <emphasis>
                y<subscript>n+1</subscript>
            </emphasis>
            .
        </para>
        <para>
            Next, we save and recompute
            <emphasis>
                y<subscript>n+1</subscript>
            </emphasis>
            with those new <emphasis>ki</emphasis>.
        </para>
        <para>
            Then, we compare the two
            <emphasis>
                y<subscript>n+1</subscript>
            </emphasis>
            and recompute it until its difference with the last computed one is inferior to the simulation parameter <emphasis>reltol</emphasis>.
        </para>
        <para>
            This process adds a significant computation time to the method, but greatly improves stability.
        </para>
        <para>
            We can see that with the <emphasis>ki</emphasis>, we progress in the derivatives of
            <emphasis>
                y<subscript>n</subscript>
            </emphasis>
            . So in <emphasis>k3</emphasis>, we are approximating
            <emphasis>
                y<superscript>(3)</superscript><subscript>n</subscript>
            </emphasis>
            , thus making an error in
            <emphasis>
                O(h<superscript>4</superscript>)
            </emphasis>
            . But choosing the right coefficients in the computation of the <emphasis>ki</emphasis> (notably the
            <emphasis>
                a<subscript>ij</subscript>
            </emphasis>
            ) makes us gain an order, thus making a per-step total error in
            <emphasis>
                O(h<superscript>5</superscript>)
            </emphasis>
            .
        </para>
        <para>
            So the total error is
            <emphasis>
                number of steps * O(h<superscript>5</superscript>)
            </emphasis>
            . And since <emphasis>number of steps = interval size / h</emphasis> by definition, the total error is in
            <emphasis>
                O(h<superscript>4</superscript>)
            </emphasis>
            .
        </para>
        <para>
            That error analysis baptized the method <emphasis>implicit Runge-Kutta 4(5)</emphasis>:
            <emphasis>
                O(h<superscript>5</superscript>)
            </emphasis>
            per step,
            <emphasis>
                O(h<superscript>4</superscript>)
            </emphasis>
            in total.
        </para>
        <para>
            Although the solver works fine for <link linkend="Simulatemenu_Menu_entries">max step size</link> up to
            <emphasis>
                10<superscript>-3</superscript>
            </emphasis>
            , rounding errors sometimes come into play as we approach
            <emphasis>
                4*10<superscript>-4</superscript>
            </emphasis>
            . Indeed, the interval splitting cannot be done properly and we get capricious results.
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <para>
            <link type="scilab" linkend="scilab.xcos/xcos/examples/solvers/ODE_Example.zcos">
                <inlinemediaobject>
                    <imageobject>
                        <imagedata align="center" fileref="../../../examples/solvers/ODE_Example.zcos" valign="middle"/>
                    </imageobject>
                </inlinemediaobject>
            </link>
            <scilab:image><![CDATA[
loadScicos();
loadXcosLibs();
importXcosDiagram(SCI + "/modules/xcos/examples/solvers/ODE_Example.zcos");
scs_m.props.tol(2) = 10^-5;
scs_m.props.tol(6) = 7;
scs_m.props.tol(7) = 10^-2;
try xcos_simulate(scs_m, 4); catch disp(lasterror()); end
]]></scilab:image>
        </para>
        <para>
            The integral block returns its continuous state, we can evaluate it with <emphasis>implicit RK</emphasis> by running the example:
        </para>
        <para>
            <programlisting language="example"><![CDATA[
      // Import the diagram and set the ending time
      loadScicos();
      loadXcosLibs();
      importXcosDiagram("SCI/modules/xcos/examples/solvers/ODE_Example.zcos");
      scs_m.props.tf = 5000;

      // Select the solver implicit RK and set the precision
      scs_m.props.tol(2) = 10^-10;
      scs_m.props.tol(6) = 7;
      scs_m.props.tol(7) = 10^-2;

      // Start the timer, launch the simulation and display time
      tic();
      try xcos_simulate(scs_m, 4); catch disp(lasterror()); end
      t = toc();
      disp("Time for implicit Runge-Kutta:", t);
      ]]></programlisting>
        </para>
        <para>
            The Scilab console displays:
            <screen><![CDATA[
Time for implicit Runge-Kutta:
 8.911
            ]]></screen>
        </para>
        <para>
            Now, in the following script, we compare the time difference between <emphasis>implicit RK</emphasis> and <emphasis>CVode</emphasis> by running the example with the five solvers in turn:
            <link type="scilab" linkend ="scilab.scinotes/xcos/examples/solvers/integImpRK.sce">
                Open the script
            </link>
        </para>
        <para>
            <screen><![CDATA[
Time for BDF / Newton:
 18.894

Time for BDF / Functional:
 18.382

Time for Adams / Newton:
 10.368

Time for Adams / Functional:
 9.815

Time for implicit Runge-Kutta:
 6.652
            ]]></screen>
        </para>
        <para>
            These results show that on a nonstiff problem, for relatively same precision required and forcing the same step size, <emphasis>implicit Runge-Kutta</emphasis> competes with <emphasis>Adams / Functional</emphasis>.
        </para>
        <para>
            Variable-size step ODE solvers are not appropriate for deterministic real-time applications because the computational overhead of taking a time step varies over the course of an application.
        </para>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="LSodar">LSodar</link>
            </member>
            <member>
                <link linkend="CVode">CVode</link>
            </member>
            <member>
                <link linkend="IDA">IDA</link>
            </member>
            <member>
                <link linkend="RK">Runge-Kutta 4(5)</link>
            </member>
            <member>
                <link linkend="DoPri">Dormand-Prince 4(5)</link>
            </member>
            <member>
                <link linkend="CRANI">Crank-Nicolson 2(3)</link>
            </member>
            <member>
                <link linkend="DDaskr">DDaskr</link>
            </member>
            <member>
                <link linkend="Comparisons">Comparisons</link>
            </member>
            <member>
                <link linkend="ode_discrete">ode_discrete</link>
            </member>
            <member>
                <link linkend="ode_root">ode_root</link>
            </member>
            <member>
                <link linkend="odedc">odedc</link>
            </member>
            <member>
                <link linkend="dae">dae</link>
            </member>
        </simplelist>
    </refsection>
    <refsection>
        <title>Bibliography</title>
        <para>
            Journal of Computational Physics, Volume 233, January 2013, Pages 315-323 <ulink url="http://dl.acm.org/citation.cfm?id=2397727.2397975&amp;coll=DL&amp;dl=GUIDE&amp;CFID=295003167&amp;CFTOKEN=37159263">A low-dispersion and low-dissipation implicit Runge-Kutta scheme</ulink>
        </para>
        <para>
            <ulink url="https://computation.llnl.gov/casc/sundials/documentation/documentation.html">Sundials Documentation</ulink>
        </para>
    </refsection>
    <refsection>
        <title>History</title>
        <revhistory>
            <revision>
                <revnumber>5.4.1</revnumber>
                <revdescription>Implicit Runge-Kutta 4(5) solver added</revdescription>
            </revision>
        </revhistory>
    </refsection>
</refentry>