1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="daskr" xml:lang="en">
18 <refname>daskr</refname>
19 <refpurpose>DAE solver with zero crossing</refpurpose>
23 <synopsis>[r, nn [, hd]] = daskr(x0, t0, t [, atol [, rtol]], res [, jac], ng, surf [, info [, psol] [, pjac]] [, hd])</synopsis>
26 <title>Arguments</title>
32 is either <literal>y0</literal> (<literal>ydot0</literal> is
33 estimated by <literal>daskr</literal> with zero as first estimate)
34 or the matrix <literal>[y0 ydot0]</literal>.
35 <literal>g(t, y0, ydot0)</literal> must be equal to zero.
36 If you only know an estimate of <literal>ydot0</literal>, set
37 <literal>info(7)=1</literal>.
43 <para>a real column vector of initial conditions.</para>
49 <para>a real column vector of the time derivative of
50 <literal>y</literal> at <literal>t0</literal> (may be an estimate).
60 <para>a real number, it is the initial instant.</para>
66 <para>a real scalar or vector. Gives instants for which you want the
67 solution. Note that you can get solution at each daskr's step point
68 by setting <literal>info(2)=1</literal>.
73 <term>atol, rtol</term>
75 <para>real scalars or column vectors of same size as
76 <literal>y</literal> or both of size 1. <literal>atol</literal> and <literal>rtol</literal> give respectively
77 absolute and relative error tolerances of solution. If vectors, the
78 tolerances are specified for each component of
87 <link linkend="external">external</link> (function, list or string). Computes the value of
88 <literal>g(t, y, ydot)</literal>. It may be :
92 <para>A Scilab function.</para>
93 <para>Its syntax must be
94 <literal>[r, ires] = res(t, y, ydot)</literal> and must return the residual
95 <literal>r = g(t, y, ydot)</literal> and error flag
96 <literal>ires</literal>. <literal>ires = 0</literal> if
97 <literal>res</literal> succeeds to compute <literal>r</literal>,
98 <literal>ires = -1</literal> if residual is locally not defined for
99 <literal>(t, y, ydot)</literal>, <literal>ires = -2</literal> if
100 parameters are out of admissible range.
105 <para>This form allows to pass parameters other than t, y, ydot to the function.
106 It must be as follows:
108 <programlisting role="no-scilab-exec"><![CDATA[
109 list(res, x1, x2, ...)
111 <para>where the syntax of the function
112 <literal>res</literal> is now
114 <programlisting role="no-scilab-exec"><![CDATA[
115 r = res(t, y, ydot, x1, x2, ...)
118 <literal>res</literal> still returns
119 <literal>r = g(t, y, ydot)</literal> as a function of
120 <literal>(t, y, ydot, x1, x2, ...)</literal>.
122 <para>Warning: this form must not be used if there is no extra
123 argument to pass to the function.
127 <para>A string.</para>
128 <para>It must refer to the name of a C function or a Fortran subroutine
131 <para>In C, the syntax must be:</para>
132 <programlisting role="no-scilab-exec"><![CDATA[
133 void res(double *t, double y[], double yd[], double r[],
134 int *ires, double rpar[], int ipar[])
136 <para>In Fortran, it must be:</para>
137 <programlisting role="no-scilab-exec"><![CDATA[
138 subroutine res(t, y, yd, r, ires, rpar, ipar)
139 double precision t, y(*), yd(*),r(*),rpar(*)
140 integer ires, ipar(*)
143 The <literal>rpar</literal> and <literal>ipar</literal>
144 arrays must be present but cannot be used.
154 <link linkend="external">external</link> (function, list or string).
155 Computes the value of <literal>dg/dy + cj*dg/dydot</literal> for a given value of parameter
156 <literal>cj</literal>.
160 <para>A Scilab function.</para>
161 <para>Its syntax must be
162 <literal>r = jac(t, y, ydot, cj)</literal> and must return
163 <literal>r = dg(t, y, ydot)/dy + cj*dg(t, y, ydot)/dydot</literal> where
164 <literal>cj</literal> is a real scalar.
169 <para>It must be as follows</para>
170 <programlisting role="no-scilab-exec"><![CDATA[
171 list(jac, x1, x2, ...)
173 <para>where the syntax of the function
174 <literal>jac</literal> is now
176 <programlisting role="no-scilab-exec"><![CDATA[
177 r=jac(t, y, ydot, cj, x1, x2,...)
180 <literal>jac</literal> still returns
181 <literal>dg/dy + cj*dg/dydot</literal> as a function of
182 <literal>(t, y, ydot, cj, x1, x2, ...)</literal>.
186 <para>A character string.</para>
187 <para>It must refer to the name of a C function or a Fortran subroutine linked with Scilab
189 <para>In C, the syntax must be:</para>
190 <programlisting role="no-scilab-exec"><![CDATA[
191 void jac(double *t, double y[], double yd[], double pd[],
192 double *cj, double rpar[], int ipar[])
194 <para>In Fortran, it must be:</para>
195 <programlisting role="no-scilab-exec"><![CDATA[
196 subroutine jac(t, y, yd, pd, cj, rpar, ipar)
197 double precision t, y(*), yd(*), pd(*), cj, rpar(*)
208 <link linkend="external">external</link> (function, list or string).
209 Computes the value of the column vector <literal>surf(t, y)</literal> with
210 <literal>ng</literal> components. Each component defines a surface.
211 It may be defined by:
215 <para>A Scilab function.</para>
216 <para>Its syntax must be
217 <literal>surf(t, y)</literal>
222 <para>It must be as follows</para>
223 <programlisting role="no-scilab-exec"><![CDATA[
224 list(surf, x1, x2, ...)
226 <para>where the syntax of the function
227 <literal>surf</literal> is now
229 <programlisting role="no-scilab-exec"><![CDATA[
230 r = surf(t, y, x1, x2, ...)
234 <para>A character string.</para>
235 <para>It must refer to the name of a C function or a Fortran subroutine linked with Scilab.
237 <para>In C, the syntax must be:</para>
238 <programlisting role="no-scilab-exec"><![CDATA[
239 void surf(int *ny, double *t, double y[], int *ng, double gout[])
241 <para>In Fortran, it must be:</para>
242 <programlisting role="no-scilab-exec"><![CDATA[
243 subroutine surf(ny, t, y, ng, gout)
244 double precision t, y(*), gout(*)
255 list which contains <literal>14</literal> elements. Default value is
256 <literal>list([], 0, [], [], [], 0, [], 0, [], 0, 0, [], [], 1)</literal>.
262 <para>real scalar which gives the maximum time for which
263 <literal>g</literal> is allowed to be evaluated or an empty matrix
264 <literal>[]</literal> if no limits imposed for time.
272 flag which indicates if <literal>daskr</literal> returns
273 its intermediate computed values (<literal>= 1</literal>)
274 or only the user specified time point values
275 (<literal>= 0</literal>).
283 <literal>2</literal> components vector which give the
284 definition <literal>[ml,mu]</literal> of band matrix computed
285 by <literal>jac</literal>; <literal>r(i - j + ml + mu + 1,j) = "dg(i)/dy(j)+cj*dg(i)/dydot(j)"</literal>.
286 If <literal>jac</literal> returns a full matrix set
287 <literal>info(3)=[]</literal>.
289 <literal>info(8)=1</literal>.
296 <para>real scalar which gives the maximum step size. Set
297 <literal>info(4)=[]</literal> if no limitation.
304 <para>real scalar which gives the initial step size. Set
305 <literal>info(5)=[]</literal> if not specified.
313 set <literal>info(6)=1</literal> if the solution is
314 known to be non negative, else set
315 <literal>info(6)=0</literal>.
323 if ydot0 is set so that
324 <literal>g(t0, y0, ydot0) = 0</literal> then set
325 <literal>info(7)=[]</literal>. Otherwise, set
326 <literal>info(7)=[+-1, ..., +-1]</literal>, with
327 <literal>info(7)(i) = 1</literal> if y(i) is a differential variable and
328 <literal>info(7)(i) = -1</literal> if y(i) is an algebraic variable
329 (if its derivatives do not appear explicitly in the function g(t, y, ydot)).
337 direct / Krylov method. Set <literal>info(8)=1</literal> and provide a routine in <literal>psol</literal>
338 if you want the solver to use Krylov iterations, else (daskr's direct method) set
339 <literal>info(8)=0</literal>.
347 Krylov parameters. Treat as dummy argument if you have set
348 <literal>info(8)=0</literal>. Otherwise, set
349 <literal>info(9)=[]</literal> or
350 <literal>info(9)=[maxl kmp nrmax epli]</literal>, where:
353 - maxl = maximum number of iterations in the GMRes algorithm (default
354 <literal>min(5, neq)</literal>),
357 - kmp = number of vectors on which orthogonalization is done in the GMRes algorithm
361 - nrmax = maximum number of restarts of the GMRes algorithm per nonlinear iteration
362 (default <literal>5</literal>),
365 - epli = convergence test constant in GMRes algorithm (default <literal>0.05</literal>).
370 <term>info(10)</term>
373 initial conditions. Treat as dummy argument if
374 <literal>info(7)=[]</literal>. Set
375 <literal>info(10)=1</literal> if the solver should stop right after
376 computation of the initial conditions, else set
377 <literal>info(10)=0</literal>.
382 <term>info(11)</term>
385 preconditioner computation and LU-factorization routine for <literal>psol</literal>.
386 Treat as dummy argument if <literal>info(8)=0</literal>. Set
387 <literal>info(11)=1</literal> and provide a <literal>pjac</literal> routine if the
388 <link linkend="external">external</link> <literal>psol</literal> should use a specific routine, else set
389 <literal>info(11)=0</literal>.
394 <term>info(12)</term>
397 if you wish to control errors locally on all the variables then set
398 <literal>info(12)=[]</literal>. Otherwise, set
399 <literal>info(12)=[+-1, ..., +-1]</literal>, with
400 <literal>info(12)(i) = 1</literal> if y(i) is a differential variable and
401 <literal>info(12)(i) = -1</literal> if y(i) is an algebraic variable
402 (if its derivatives do not appear explicitly in the function g(t, y, ydot)).
407 <term>info(13)</term>
410 heuristic parameters. Treat as dummy argument if
411 <literal>info(7)=[]</literal>. Otherwise, set
412 <literal>info(13)=[]</literal> or
413 <literal>info(13)=[mxnit mxnj mxnh lsoff stptol epinit]</literal>, where:
416 - mxnit = maximum number of Newton iterations per Jacobian or preconditioner evaluation (default
417 <literal>5</literal> if <literal>info(8)=0</literal>, <literal>15</literal> otherwise),
420 - mxnj = maximum number of Jacobian or preconditioner evaluations (default
421 <literal>6</literal> if <literal>info(8)=0</literal>, <literal>2</literal> otherwise),
424 - mxnh = maximum number of values of the artificial stepsize
425 parameter <literal>h</literal> to be tried if info(7) ≠ []
426 (default <literal>5</literal>),
429 - lsoff = flag to turn off the linesearch algorithm (lsoff = 0 means linesearch is on, lsoff = 1 means it is turned off)
430 (default <literal>0</literal>),
433 - stptol = minimum scaled step in linesearch algorithm (default <literal>(unit roundoff)^(2/3)</literal>),
436 - epinit = swing factor in the Newton iteration convergence test (default <literal>0.01</literal>).
441 <term>info(14)</term>
444 verbosity. Set <literal>info(14)=1</literal> for minimal extra printing,
445 <literal>info(14)=2</literal> for full printing, else set
446 <literal>info(14)=0</literal>.
457 <link linkend="external">external</link> (function, list or string). Solves a linear system
458 <literal>P*x = b</literal>, with P being the factored preconditioner that routine <literal>pjac</literal>
459 computed beforehand and stored in <literal>wp</literal> and <literal>iwp</literal>.
463 <para>A Scilab function.</para>
464 <para>Its syntax must be
465 <literal>[r, ier] = psol(wp, iwp, b)</literal> and must return the solution of the system in
466 <literal>r</literal> and an error flag <literal>ier</literal>.
471 <para>It must be as follows:</para>
472 <programlisting role="no-scilab-exec"><![CDATA[
473 list(psol, x1, x2, ...)
476 where the syntax of <literal>psol</literal> is now
478 <programlisting role="no-scilab-exec"><![CDATA[
479 psol(wp, iwp, b, x1, x2, ...)
482 <literal>psol</literal> still returns the solution in <literal>r</literal>.
486 <para>A character string.</para>
487 <para>It must refer to the name of a C function or a Fortran subroutine linked with Scilab
489 <para>In C, the syntax must be:</para>
490 <programlisting role="no-scilab-exec"><![CDATA[
491 void psol (int*neq, double*t, double*y, double*ydot, double*savr,
492 double*wk, double*cj, double*wght, double*wp, int*iwp, double*b, double*eplin, int*ier, double*rpar, int*ipar)
494 where the arrays <literal>wp</literal> and <literal>iwp</literal> contain matrix elements of LU-factored preconditioner
495 <literal>P</literal>, <literal>wp</literal> being the values and
496 <literal>iwp</literal> the pivots used in the factorization.
497 <para>In Fortran, it must be:</para>
498 <programlisting role="no-scilab-exec"><![CDATA[
499 subroutine psol (neq, t, y, ydot, savr, wk, cj, wght,
500 wp, iwp, b, eplin, ier, rpar, ipar)
501 double precision t,y(*), ydot(*), savr(*), wk(*), cj, wght(*), wp(*),
503 integer neq, iwp(*), ier, ipar(*)
513 <link linkend="external">external</link> (function, list or string). Computes the value of
514 <literal>dg/dy + cj*dg/dydot</literal> for a given value of parameter
515 <literal>cj</literal> and LU-factorizes it in two arrays, real and integer.
519 <para>A Scilab function.</para>
520 <para>Its syntax must be
521 <literal>[wp, iwp, ires] = pjac(neq, t, y, ydot, h, cj, rewt, savr)</literal> and in return,
522 the arrays <literal>wp</literal> and <literal>iwp</literal> must contain all factored preconditioner information.
527 <para>It must be as follows</para>
528 <programlisting role="no-scilab-exec"><![CDATA[
529 list(pjac, x1, x2, ...)
532 where the syntax of <literal>pjac</literal> is
534 <programlisting role="no-scilab-exec"><![CDATA[
535 pjac(neq, t, y, ydot, h, cj, rewt, savr, x1, x2,...)
538 <literal>pjac</literal> still returns factorized
539 <literal>dg/dy + cj*dg/dydot</literal> as a function of
540 <literal>(neq, t, y, ydot, h, cj, rewt, savr, x1, x2, ...)</literal>.
544 <para>A character string.</para>
545 <para>It must refer to the name of a C function or a Fortran subroutine linked with Scilab
547 <para>In C, the syntax must be:</para>
548 <programlisting role="no-scilab-exec"><![CDATA[
549 void pjac (double*res, int*ires, int*neq, double*t, double*y, double*ydot, double*rewt, double*savr,
550 double*wk, double*h, double*cj, double*wp, int*iwp, int*ier, double*rpar, int*ipar)
552 <para>In Fortran, it must be:</para>
553 <programlisting role="no-scilab-exec"><![CDATA[
554 subroutine pjac (res, ires, neq, t, y, ydot, rewt, savr,
555 wk, h, cj, wp, iwp, ier, rpar, ipar)
556 double precision res(*), t, y(*), ydot(*), rewt(*), savr(*),
557 wk(*), h, cj, wp(*), rpar(*)
558 integer ires, neq, iwp(*), ier, ipar(*)
568 real vector which allows to store the <literal>daskr</literal>
569 context and to resume integration.
577 real matrix. Each column is the vector <literal>[t; x(t); xdot(t)]</literal> where
578 <literal>t</literal> is the time index for which the solution has been computed,
579 <literal>x(t)</literal> is the value of the computed solution,
580 <literal>xdot(t)</literal> is the derivative of the computed solution.
588 a vector with two entries <literal>[times num]</literal>,
589 <literal>times</literal> is the value of the time at which the surface is crossed,
590 <literal>num</literal> is the number of the crossed surface.
597 <title>Description</title>
598 <para>Solution of the implicit differential equation:</para>
599 <programlisting role="no-scilab-exec"><![CDATA[
601 y(t0) = y0 and ydot(t0) = ydot0
603 <para>Returns the surface crossing instants and the number of the surface
604 reached in <literal>nn</literal>.
606 <para>Detailed examples can be found in SCI/modules/differential_equations/tests/unit_tests/daskr.tst</para>
609 <title>Examples</title>
610 <programlisting role="example"><![CDATA[
611 // dy/dt = ((2*log(y)+8)/t-5)*y, y(1) = 1, 1 <= t <= 6
612 // g1 = ((2*log(y)+8)/t-5)*y
613 // g2 = log(y) - 2.2491
614 y0 = 1; t = 2:6; t0 = 1; y0d = 3;
615 atol = 1.d-6; rtol = 0; ng = 2;
617 deff('[delta, ires] = res1(t, y, ydot)', 'ires = 0; delta = ydot-((2*log(y)+8)/t-5)*y')
618 deff('[rts] = gr1(t, y)', 'rts = [((2*log(y)+8)/t-5)*y; log(y)-2.2491]')
620 [yy, nn] = daskr([y0, y0d], t0, t, atol, rtol, res1, ng, gr1);
623 // Should return nn = [2.4698972 2]
626 <refsection role="see also">
627 <title>See also</title>
628 <simplelist type="inline">
630 <link linkend="ode">ode</link>
633 <link linkend="dasrt">dasrt</link>
636 <link linkend="dassl">dassl</link>
639 <link linkend="impl">impl</link>
642 <link linkend="call">call</link>
645 <link linkend="link">link</link>
648 <link linkend="external">external</link>
653 <title>History</title>
656 <revnumber>5.5.0</revnumber>
657 <revdescription>daskr solver added</revdescription>