Download data/help/1-CVode.xml from notsn/XCos_MCP: direct link, hf CLI and curl.
- Browser
- Download file 12.5 kB
-
https://huggingface.co/spaces/notsn/XCos_MCP/resolve/main/data/help/1-CVode.xml
- Command line
-
hf download hf://spaces/notsn/XCos_MCP/data/help/1-CVode.xml
-
curl -L -o 1-CVode.xml https://huggingface.co/spaces/notsn/XCos_MCP/resolve/main/data/help/1-CVode.xml
12.5 kB
| <!-- | |
| * 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="CVode"> | |
| <refnamediv> | |
| <refname>CVode</refname> | |
| <refpurpose> | |
| <emphasis>CVode</emphasis> (short for C-language Variable-coefficients ODE solver) is a numerical solver providing an efficient and stable method to solve Ordinary Differential Equations (ODEs) Initial Value Problems. It uses either <emphasis>BDF</emphasis> or <emphasis>Adams</emphasis> as implicit integration method, and <emphasis>Newton</emphasis> or <emphasis>Functional</emphasis> iterations. | |
| </refpurpose> | |
| </refnamediv> | |
| <refsection> | |
| <title>Description</title> | |
| <para> | |
| Called by <link linkend="xcos">xcos</link>, <emphasis>CVode</emphasis> (short for C-language Variable-coefficients ODE solver) is a numerical solver providing an efficient and stable 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> | |
| Starting with | |
| <emphasis> | |
| y<subscript>0</subscript> | |
| </emphasis> | |
| , <emphasis>CVode</emphasis> approximates | |
| <emphasis> | |
| y<subscript>n+1</subscript> | |
| </emphasis> | |
| with the formula: | |
| </para> | |
| <para> | |
| <latex> | |
| \begin{eqnarray} | |
| \sum_{i=0}^{K_1} \alpha_{n,i} y_{n-i} + h_n\sum_{i=0}^{K_2} \beta_{n,i} \dot{y}_{n-i} = 0,\hspace{10 mm} (1) | |
| \end{eqnarray} | |
| </latex> | |
| <para> | |
| with | |
| <emphasis> | |
| y<subscript>n</subscript> | |
| </emphasis> | |
| the approximation of | |
| <emphasis> | |
| y(t<subscript>n</subscript>) | |
| </emphasis> | |
| , and | |
| <emphasis> | |
| h<subscript>n</subscript> | |
| </emphasis> | |
| = | |
| <emphasis> | |
| t<subscript>n</subscript> - t<subscript>n-1</subscript> | |
| </emphasis> | |
| the step size. | |
| </para> | |
| </para> | |
| <para> | |
| These implicit methods are characterized by their respective order <emphasis>q</emphasis>, which indicates the number of intermediate points required to compute | |
| <emphasis> | |
| y<subscript>n+1</subscript> | |
| </emphasis> | |
| . | |
| </para> | |
| <para> | |
| This is where the difference between <emphasis>BDF</emphasis> and <emphasis>Adams</emphasis> intervenes (<emphasis>Backward Differentiation Formula</emphasis> and <emphasis>Adams-Moulton formula</emphasis>): | |
| </para> | |
| <para> | |
| <caution> | |
| If the problem is stiff, the user should select <emphasis>BDF</emphasis>: | |
| </caution> | |
| </para> | |
| <itemizedlist> | |
| <listitem> | |
| <emphasis>q</emphasis>, the order of the method, is set between 1 and 5 (automated), | |
| </listitem> | |
| <listitem> | |
| <emphasis>K1 = q</emphasis> and <emphasis>K2 = 0</emphasis>. | |
| </listitem> | |
| </itemizedlist> | |
| <para> | |
| In the case of nonstiffness, <emphasis>Adams</emphasis> is preferred: | |
| </para> | |
| <itemizedlist> | |
| <listitem> | |
| <emphasis>q</emphasis> is set between 1 and 12 (automated), | |
| </listitem> | |
| <listitem> | |
| <emphasis>K1 = 1</emphasis> and <emphasis>K2 = q</emphasis>. | |
| </listitem> | |
| </itemizedlist> | |
| <para> | |
| The coefficients are fixed, uniquely determined by the method type, its order, the history of the step sizes, and the normalization | |
| <emphasis> | |
| α<subscript>n, 0</subscript> = -1 | |
| </emphasis> | |
| . | |
| </para> | |
| <para> | |
| For either choice and at each step, injecting this integration in <emphasis>(1)</emphasis> yields the nonlinear system: | |
| </para> | |
| <para> | |
| <latex scilab:localized="true"> | |
| G(y_n)\equiv y_n-h_n\beta_{n,0}f(t_n,y_n)-a_n=0, \hspace{2 mm} where \hspace{2 mm} a_n\equiv \sum_{i>0} (\alpha_{n,i} y_{n-i} + h_n\beta_{n,i}\dot{y}_{n-i}) | |
| </latex> | |
| </para> | |
| <para> | |
| This system can be solved by either <emphasis>Functional</emphasis> or <emphasis>Newton</emphasis> iterations, described hereafter. | |
| </para> | |
| <para> | |
| In both following cases, the initial "predicted" | |
| <emphasis> | |
| y<subscript>n(0)</subscript> | |
| </emphasis> | |
| is explicitly computed from the history data, by adding derivatives. | |
| </para> | |
| <itemizedlist> | |
| <para> </para> | |
| <listitem> | |
| <emphasis role="bold">Functional:</emphasis> this method only involves evaluations of <emphasis>f</emphasis>, it simply computes | |
| <emphasis> | |
| y<subscript>n(0)</subscript> | |
| </emphasis> | |
| by iterating the formula: | |
| <para> | |
| <latex> | |
| y_{n(m+1)} = h_n β_{n,0} f(t_n,y_{n(m)}) + a_n | |
| </latex> | |
| <latex scilab:localized="true"> | |
| where \hspace{2 mm} a_n\equiv \sum_{i>0} (\alpha_{n,i} y_{n-i} + h_n\beta_{n,i}\dot{y}_{n-i}) | |
| </latex> | |
| </para> | |
| </listitem> | |
| <para> </para> | |
| <listitem> | |
| <emphasis role="bold">Newton:</emphasis> here, we use an implemented direct dense solver on the linear system: | |
| <para> | |
| <latex scilab:localized="true"> | |
| M[y_{n(m+1)}-y_{n(m)}]=-G(y_{n(m)}), \hspace{4 mm} M \approx I-\gamma J, \hspace{2 mm} J=\frac{\partial f}{\partial y}, \hspace{2 mm} and \hspace{2 mm} \gamma = h_n\beta_{n,0} | |
| </latex> | |
| </para> | |
| </listitem> | |
| </itemizedlist> | |
| <para> | |
| In both situations, <emphasis>CVode</emphasis> uses the history array to control the local error | |
| <emphasis> | |
| y<subscript>n(m)</subscript> - y<subscript>n(0)</subscript> | |
| </emphasis> | |
| and recomputes | |
| <emphasis> | |
| h<subscript>n</subscript> | |
| </emphasis> | |
| if that error is not satisfying. | |
| </para> | |
| <para> | |
| <emphasis role="bold"> | |
| The recommended choices are <emphasis>BDF / Newton</emphasis> for stiff problems and <emphasis>Adams / Functional</emphasis> for the nonstiff ones. | |
| </emphasis> | |
| </para> | |
| <para> | |
| The function is called in between activations, because a discrete activation may change the system. | |
| </para> | |
| <para> | |
| Following the criticality of the event (its effect on the continuous problem), we either relaunch the solver with different start and final times as if nothing happened, or, if the system has been modified, we need to "cold-restart" the problem by reinitializing it anew and relaunching the solver. | |
| </para> | |
| <para> | |
| Averagely, <emphasis>CVode</emphasis> accepts tolerances up to 10<superscript>-16</superscript>. Beyond that, it returns a <emphasis>Too much accuracy</emphasis> requested error. | |
| </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(6) = 1; | |
| 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>BDF / Newton</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 BDF / Newton | |
| scs_m.props.tol(6) = 1; | |
| // 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 BDF / Newton:", t); | |
| ]]></programlisting> | |
| </para> | |
| <para> | |
| The Scilab console displays: | |
| <screen><![CDATA[ | |
| Time for BDF / Newton: | |
| 13.438 | |
| ]]></screen> | |
| </para> | |
| <para> | |
| Now, in the following script, we compare the time difference between the methods by running the example with the four solvers in turn: | |
| <link type="scilab" linkend ="scilab.scinotes/xcos/examples/solvers/integCVode.sce"> | |
| Open the script | |
| </link> | |
| </para> | |
| <para> | |
| Results: | |
| <screen language="example"><![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 | |
| ]]></screen> | |
| </para> | |
| <para> | |
| The results show that for a simple nonstiff continuous problem, <emphasis>Adams / Functional</emphasis> is fastest. | |
| </para> | |
| </refsection> | |
| <refsection role="see also"> | |
| <title>See also</title> | |
| <simplelist type="inline"> | |
| <member> | |
| <link linkend="LSodar">LSodar</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="ImpRK">Implicit Runge-Kutta 4(5)</link> | |
| </member> | |
| <member> | |
| <link linkend="CRANI">Crank-Nicolson 2(3)</link> | |
| </member> | |
| <member> | |
| <link linkend="IDA">IDA</link> | |
| </member> | |
| <member> | |
| <link linkend="DDaskr">DDaskr</link> | |
| </member> | |
| <member> | |
| <link linkend="Comparisons">Comparisons</link> | |
| </member> | |
| <member> | |
| <link linkend="ode">ode</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> | |
| <ulink url="https://computation.llnl.gov/casc/sundials/documentation/documentation.html">Sundials Documentation</ulink> | |
| </para> | |
| </refsection> | |
| </refentry> | |