rosenbrock - Maple Help

dsolve/numeric/rosenbrock

find numerical solution of stiff ordinary differential equations

 Calling Sequence dsolve($\mathrm{odesys}$, numeric, method=rosenbrock, vars, options) dsolve(numeric, method=rosenbrock, procopts, options)

Parameters

 odesys - set or list; ordinary differential equation(s) and initial conditions numeric - literal name; instruct dsolve to find a numerical solution method=rosenbrock - literal equation; numerical method to use vars - (optional) any indeterminate function of one variable, or a set or list of them, representing the unknowns of the ODE problem options - (optional) equations of the form keyword = value procopts - options used to specify the ODE system using a procedure (procedure, initial, start, number, procvars, and jacobian). For more information on all but the last of these, see dsolve/numeric/IVP.

Description

 • The dsolve command with options numeric and method=rosenbrock finds a numerical solution using an Implicit Rosenbrock third-fourth order Runge-Kutta method with degree three interpolant. This is the default method of the type=numeric solution for initial value problems when the stiff argument is used.

Modes of Operation

 • The rosenbrock method has two distinct modes of operation (for procedure-type outputs).
 • With the range option specified
 When used with the range option, the method computes the solution for the IVP over the specified range, storing the solution information internally, and uses that information to rapidly interpolate the desired solution value for any call to the returned procedure(s).
 Though possible, it is not recommended that the returned procedure be called for points outside the specified range.
 This method can be used in combination with the refine option of odeplot to produce an adaptive plot (that is, odeplot uses the precomputed points to produce the plot when refine is specified.)
 It is not recommended that this method be used for problems in which the solution can become singular, as each step is stored, and many steps may be taken when near a singularity, so memory usage can become a significant issue.
 The storage of the interpolant in use by this method can be disabled by using the interpolation=false option described below. This may be desirable for high accuracy solutions where storage of the interpolant (in addition to the discrete solution) requires too much memory. Disabling the interpolant is not generally recommended as the solution values will be obtained from an interpolation of the 4 closest points, and does not necessarily provide an interpolant with order 3 error.
 • Without the range option specified
 When used without the range option, the IVP solution values are not stored, but rather computed when requested.
 Because not all solution values are stored, computation must restart at the initial values whenever a point is requested between the initial point and the most recently computed point (to avoid reversal of the integration direction), so it is advisable to collect solution values moving away from the initial value.

Options

 • The following options are available for the rosenbrock method.

 'output' = keyword or array 'known' = name or list of names 'abserr' = numeric 'relerr' = numeric 'initstep' = numeric 'interr' = boolean 'maxfun' = integer 'number' = integer 'procedure' = procedure 'jacobian' = procedure 'start' = numeric 'initial' = array 'procvars' = list 'startinit' = boolean 'implicit' = boolean 'optimize' = boolean 'compile' = boolean or auto 'range' = numeric..numeric 'events' = list 'event_pre' = keyword 'event_maxiter' = integer 'event_iterate' = keyword 'event_initial' = boolean 'complex' = boolean

 output
 Specifies the desired output from dsolve. The keywords procedurelist, listprocedure, or operator  provide procedure-type output, the keyword piecewise provides output in the form of piecewise functions over a specified range of independent variable values, and a 1-D array or Array provide output at fixed values of the independent variable. For details, see dsolve/numeric.
 known
 Specifies user-defined known functions, and basic usage is discussed in dsolve/numeric. As mentioned there, in addition to the requirement of a procedural definition for the function that evaluates with numeric arguments, otherwise not, this method also requires a diff/ rule.
 This diff/ rule must provide the partial derivatives of the function with respect to the independent variables, dependent variables, and derivatives that are used to compute the known function. Note: The key word here is partial, and an example can be found below. This is in contrast to the taylorseries method, for which the diff rule with respect to the independent variable must provide a total derivative.
 Only a single partial derivative with respect to the independent variables, dependent variables, and derivatives is required for each known function, so these can be coded as procedures themselves, not requiring diff/ rules.
 abserr, relerr, and initstep
 Specify the desired accuracy of the solution, and the starting step size for the method, and are discussed in dsolve/Error_Control. The default value for rosenbrock for both the abserr and relerr options is 1e-6. The value for initstep, if not specified, is determined by the method, taking into account the local behavior of the ODE system.
 interr
 By default this is set to true, and controls whether the solution interpolant error (including the interpolant on index-1 variables for DAE problems) is integrated into the error control. When set to $\mathrm{false}$, areas where the solutions is varying rapidly (e.g. a discontinuity in a derivative due to a piecewise) may have a much larger solution error than dictated by the specified error tolerances. When set to $\mathrm{true}$, the step size is reduced to minimize error in these regions, but for problems where there is a jump discontinuity in the variables, the integration may fail with an error indicating that a singularity is present. In the latter case where an error is thrown, it may be advantageous to model the discontinuities using events (see dsolve/Events).
 maxfun
 Specifies the maximum number of evaluations of the right-hand side of the first order ODE system. This option can be disabled by specifying $\mathrm{maxfun}=0$. The default value for rosenbrock is $30000$.
 number, procedure, start, initial, and procvars
 These options are used to specify the IVP using procedures. For more information, see dsolve/numeric/IVP.
 jacobian
 This option can be used in combination with the procedure and related options to specify a procedure-defined jacobian. If not provided, a jacobian is computed from the input system, or using the input procedure by evaluating it with indeterminate values of the independent and dependent variables, and utilizing the result. Note that this approach will not work if the input procedure-form system contains conditional statements and/or loops, so in these cases use of a specified procedure-form jacobian will be necessary.
 As with the procedure option, the IVP system must first be written as a first order system (see dsolve/numeric/IVP), and from this the jacobian can be obtained. The input procedure must be of the form $\mathrm{jac}\left(x,y,\mathrm{fx},\mathrm{fy}\right)$, where $x$ is the value of the independent variable (input), $y$ is the vector of values of the dependent variables (input), $\mathrm{fx}$ is a vector of values of the derivatives of the right-hand-sides of the differential system with respect to $x$ (output), and $\mathrm{fy}$ is a matrix of values of the derivatives of the right-hand-sides of the differential system with respect to each dependent variable $y$ (output).
 As an example, consider the differential system $\frac{ⅆ}{ⅆt}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}x\left(t\right)=f\left(t,x\left(t\right),y\left(t\right)\right),\frac{ⅆ}{ⅆt}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}y\left(t\right)=g\left(t,x\left(t\right),y\left(t\right)\right)$ for some specific form of $f\left(t,x\left(t\right),y\left(t\right)\right),g\left(t,x\left(t\right),y\left(t\right)\right)$. The procedure and jacobian procedures could be defined as follows:

 prc := proc(n,t,v,vp) vp[1] := f(t,v[1],v[2]); vp[2] := g(t,v[1],v[2]); end proc: jac := proc(t,v,ft,fv) ft[1]   := D[1](f)(t,v[1],v[2]); ft[2]   := D[1](g)(t,v[1],v[2]); fv[1,1] := D[2](f)(t,v[1],v[2]); fv[1,2] := D[3](f)(t,v[1],v[2]); fv[2,1] := D[2](g)(t,v[1],v[2]); fv[2,2] := D[3](g)(t,v[1],v[2]); end proc:

 startinit,implicit, and optimize
 These options control the method and behavior of the computation. For more information on the first two, see dsolve/numeric/IVP, for the last, see dsolve/numeric.
 compile
 This option specifies that the internally generated procedures that are used to compute the numeric solution be compiled for efficiency. Note that this option will only work if $\mathrm{Digits}$ is set within the hardware precision range, and the input function contains only evalhf capable functions (e.g. only elementary mathematical functions like exp, sin, and ln).  See dsolve/Efficiency. By default this value is set to false. If set to true and a compile is not possible, an error will be thrown. If set to auto and a compile is not possible, the uncompiled procedures will be used directly.
 range
 Determines the range of values of the independent variable for which solution values are required. Use of this option significantly changes the behavior of the method for the procedure-style output types discussed in dsolve/numeric (see description of with/without range above).
 events, event_pre, event_maxiter, event_iterate, event_initial
 These options are used to specify and control the behavior of events for the numerical solution. These options are discussed in detail in dsolve/Events.
 complex
 Accepts a boolean value indicating if the problem is (or will become) complex valued. By default this is detected based on the input system and initial data, but in cases where the input system is procedure defined, or the system is initially real, it may be necessary to specify complex=true to obtain the solution. It is assumed that for an initially real system that becomes complex, the point at which this transition occurs is considered to be a singularity, so if complex=true is not specified, the integration will halt at that point.

 • By setting infolevel[dsolve] to $2$, information on the last mesh point evaluation is provided in the event of an error.
 • The rosenbrock method is capable of computing high-accuracy solutions for IVPs because the precision of the computation can be increased by changing the Digits environment variable. Care must be taken because computation of high accuracy solutions with a method that has not been designed for the task can be quite inefficient.
 • Results can be plotted by using the function odeplot in the plots package.

Examples

A stiff linear problem with eigenvalues of $-1$, $-100$, storing solution values from 0..10:

 > $\mathrm{deq1}≔\mathrm{diff}\left(y\left(t\right),t,t\right)+101\mathrm{diff}\left(y\left(t\right),t\right)+100y\left(t\right)=0:$
 > $\mathrm{ic1}≔y\left(0\right)=1,\mathrm{D}\left(y\right)\left(0\right)=-1:$
 > $\mathrm{dsol1}≔\mathrm{dsolve}\left(\left\{\mathrm{deq1},\mathrm{ic1}\right\},\mathrm{numeric},\mathrm{stiff}=\mathrm{true},\mathrm{range}=0..10\right)$
 ${\mathrm{dsol1}}{≔}{\mathbf{proc}}\left({\mathrm{x_rosenbrock}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (1)
 > $\mathrm{dsol1}\left(1\right)$
 $\left[{t}{=}{1.}{,}{y}{}\left({t}\right){=}{0.367879598211910}{,}\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({t}\right){=}{-0.367879598211910}\right]$ (2)
 > $\mathrm{dsol1}\left(10\right)$
 $\left[{t}{=}{10.}{,}{y}{}\left({t}\right){=}{0.0000454031562789614}{,}\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({t}\right){=}{-0.0000454031562789614}\right]$ (3)

A stiff nonlinear system from reactor kinetics, computing solution values as requested:

 > $\mathrm{deq2}≔\mathrm{diff}\left(u\left(t\right),t\right)=0.01-\left(1+\left(u\left(t\right)+1000\right)\left(u\left(t\right)+1\right)\right)\left(0.01+u\left(t\right)+v\left(t\right)\right),\mathrm{diff}\left(v\left(t\right),t\right)=0.01-\left(1+{v\left(t\right)}^{2}\right)\left(0.01+u\left(t\right)+v\left(t\right)\right)$
 ${\mathrm{deq2}}{≔}\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{u}{}\left({t}\right){=}{0.01}{-}\left({1}{+}\left({u}{}\left({t}\right){+}{1000}\right){}\left({u}{}\left({t}\right){+}{1}\right)\right){}\left({0.01}{+}{u}{}\left({t}\right){+}{v}{}\left({t}\right)\right){,}\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{v}{}\left({t}\right){=}{0.01}{-}\left({1}{+}{{v}{}\left({t}\right)}^{{2}}\right){}\left({0.01}{+}{u}{}\left({t}\right){+}{v}{}\left({t}\right)\right)$ (4)
 > $\mathrm{ic2}≔u\left(0\right)=0,v\left(0\right)=0:$
 > $\mathrm{dsol2}≔\mathrm{dsolve}\left(\left\{\mathrm{deq2},\mathrm{ic2}\right\},\mathrm{numeric},\mathrm{method}=\mathrm{rosenbrock}\right)$
 ${\mathrm{dsol2}}{≔}{\mathbf{proc}}\left({\mathrm{x_rosenbrock}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (5)
 > $\mathrm{dsol2}\left(1\right)$
 $\left[{t}{=}{1.}{,}{u}{}\left({t}\right){=}{-0.0199493609829511}{,}{v}{}\left({t}\right){=}{0.00996972672213670}\right]$ (6)
 > $\mathrm{dsol2}\left(\mathrm{\pi }\right)$
 $\left[{t}{=}{3.14159265358979}{,}{u}{}\left({t}\right){=}{-0.0413207162436741}{,}{v}{}\left({t}\right){=}{0.0313415353663766}\right]$ (7)

Use of the known option for multiple argument functions (requires diff rule). Using the following function

 > $f\left(x,y\left(x\right)\right)=\mathrm{Int}\left(\frac{\mathrm{exp}\left(-\frac{t\cdot 2}{100}\right)}{10},t=0..x\right)-y\left(x\right)$
 ${f}{}\left({x}{,}{y}{}\left({x}\right)\right){=}{{\int }}_{{0}}^{{x}}\frac{{{ⅇ}}^{{-}\frac{{t}}{{50}}}}{{10}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}{t}{-}{y}{}\left({x}\right)$ (8)

define 'f' as

 > f := proc(x,y) local t;    if not type(evalf(x),numeric) or       not type(evalf(y),numeric) then       'procname'(x,y);    else       evalf(Int(exp(-t*2/100)/10,t=0..x))-y;    end if; end proc;
 ${f}{≔}{\mathbf{proc}}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{t}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{not}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\left({\mathrm{type}}{}\left({\mathrm{evalf}}{}\left({x}\right){,}{\mathrm{numeric}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{type}}{}\left({\mathrm{evalf}}{}\left({y}\right){,}{\mathrm{numeric}}\right)\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{then}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{'}{\mathrm{procname}}{'}{}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{else}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{evalf}}{}\left({\mathrm{Int}}{}\left({1}{/}{10}{*}{\mathrm{exp}}{}\left({−}{1}{/}{50}{*}{t}\right){,}{t}{=}{0}{..}{x}\right)\right){-}{y}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (9)

and use the diff/ rule for the partial derivatives with respect to both x and y:

 > diff/f := proc(x,y);    if args[3]=x then       diff(x,args[3])*exp(-x*2/100)/10;    elif args[3]=y then       -1;    else       error "unable to differentiate";    end if; end proc;
 ${\mathrm{diff/f}}{≔}{\mathbf{proc}}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{args}}{[}{3}{]}{=}{x}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{then}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{1}{/}{10}{*}\left({\mathrm{diff}}{}\left({x}{,}{\mathrm{args}}{[}{3}{]}\right)\right){*}{\mathrm{exp}}{}\left({−}{1}{/}{50}{*}{x}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{elif}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{args}}{[}{3}{]}{=}{y}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{then}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{−}{1}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{else}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{error}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{"unable to differentiate"}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (10)

Using this information you can now call dsolve to obtain a solution procedure, then obtain solution values.

 > $\mathrm{dsol}≔\mathrm{dsolve}\left(\left\{\mathrm{diff}\left(y\left(x\right),x\right)=f\left(x,y\left(x\right)\right),y\left(0\right)=0\right\},\mathrm{numeric},\mathrm{known}=f,\mathrm{method}=\mathrm{rosenbrock}\right)$
 ${\mathrm{dsol}}{≔}{\mathbf{proc}}\left({\mathrm{x_rosenbrock}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (11)
 > $\mathrm{dsol}\left(10\right)$
 $\left[{x}{=}{10.}{,}{y}{}\left({x}\right){=}{0.822806857910325}\right]$ (12)

References

 Hairer, E., and Wanner, G. Solving Ordinary Differential Equations II. 2nd ed. New York: Springer, 1996.
 Shampine, L.F., and Corless, R.M. "Initial Value Problems for ODEs in Problem Solving Environments." J. Comp. Appl. Math, Vol. 125(1-2), (2000): 31-40.