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 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
|
@cindex differential equations, initial value problems
@cindex initial value problems, differential equations
@cindex ordinary differential equations, initial value problem
@cindex ODEs, initial value problems
This chapter describes functions for solving ordinary differential
equation (ODE) initial value problems. The library provides a variety
of low-level methods, such as Runge-Kutta and Bulirsch-Stoer routines,
and higher-level components for adaptive step-size control. The
components can be combined by the user to achieve the desired
solution, with full access to any intermediate steps. A driver object
can be used as a high level wrapper for easy use of low level
functions.
These functions are declared in the header file @file{gsl_odeiv2.h}.
This is a new interface in version 1.15 and uses the prefix
@code{gsl_odeiv2} for all functions. It is recommended over the
previous @code{gsl_odeiv} implementation defined in @file{gsl_odeiv.h}
The old interface has been retained under the original name for
backwards compatibility.
@menu
* Defining the ODE System::
* Stepping Functions::
* Adaptive Step-size Control::
* Evolution::
* Driver::
* ODE Example programs::
* ODE References and Further Reading::
@end menu
@node Defining the ODE System
@section Defining the ODE System
The routines solve the general @math{n}-dimensional first-order system,
@tex
\beforedisplay
$$
{dy_i(t) \over dt} = f_i (t, y_1(t), \dots y_n(t))
$$
\afterdisplay
@end tex
@ifinfo
@example
dy_i(t)/dt = f_i(t, y_1(t), ..., y_n(t))
@end example
@end ifinfo
@noindent
for @math{i = 1, \dots, n}. The stepping functions rely on the vector
of derivatives @math{f_i} and the Jacobian matrix,
@c{$J_{ij} = \partial f_i(t, y(t)) / \partial y_j$}
@math{J_@{ij@} = df_i(t,y(t)) / dy_j}.
A system of equations is defined using the @code{gsl_odeiv2_system}
datatype.
@deftp {Data Type} gsl_odeiv2_system
This data type defines a general ODE system with arbitrary parameters.
@table @code
@item int (* function) (double t, const double y[], double dydt[], void * params)
This function should store the vector elements
@c{$f_i(t,y,\hbox{\it params})$}
@math{f_i(t,y,params)} in the array @var{dydt},
for arguments (@var{t},@var{y}) and parameters @var{params}.
The function should return @code{GSL_SUCCESS} if the calculation was
completed successfully. Any other return value indicates an error. A
special return value @code{GSL_EBADFUNC} causes @code{gsl_odeiv2}
routines to immediately stop and return. If @code{function}
is modified (for example contents of @var{params}), the user must call an
appropriate reset function (@code{gsl_odeiv2_driver_reset},
@code{gsl_odeiv2_evolve_reset} or @code{gsl_odeiv2_step_reset})
before continuing. Use return values
distinct from standard GSL error codes to distinguish your function as
the source of the error.
@item int (* jacobian) (double t, const double y[], double * dfdy, double dfdt[], void * params);
@cindex Jacobian matrix, ODEs
This function should store the vector of derivative elements
@c{$\partial f_i(t,y,params) / \partial t$} @math{df_i(t,y,params)/dt}
in the array @var{dfdt} and the Jacobian matrix @c{$J_{ij}$}
@math{J_@{ij@}} in the array @var{dfdy}, regarded as a row-ordered
matrix @code{J(i,j) = dfdy[i * dimension + j]} where @code{dimension}
is the dimension of the system.
Not all of the stepper algorithms of @code{gsl_odeiv2} make use of the
Jacobian matrix, so it may not be necessary to provide this function
(the @code{jacobian} element of the struct can be replaced by a null
pointer for those algorithms).
The function should return @code{GSL_SUCCESS} if the calculation was
completed successfully. Any other return value indicates an error. A
special return value @code{GSL_EBADFUNC} causes @code{gsl_odeiv2}
routines to immediately stop and return. If @code{jacobian}
is modified (for example contents of @var{params}), the user must call an
appropriate reset function (@code{gsl_odeiv2_driver_reset},
@code{gsl_odeiv2_evolve_reset} or @code{gsl_odeiv2_step_reset})
before continuing. Use return values
distinct from standard GSL error codes to distinguish your function as
the source of the error.
@item size_t dimension;
This is the dimension of the system of equations.
@item void * params
This is a pointer to the arbitrary parameters of the system.
@end table
@end deftp
@node Stepping Functions
@section Stepping Functions
The lowest level components are the @dfn{stepping functions} which
advance a solution from time @math{t} to @math{t+h} for a fixed
step-size @math{h} and estimate the resulting local error.
@deftypefun {gsl_odeiv2_step *} gsl_odeiv2_step_alloc (const gsl_odeiv2_step_type * @var{T}, size_t @var{dim})
@tindex gsl_odeiv2_step
@tindex gsl_odeiv2_step_type
This function returns a pointer to a newly allocated instance of a
stepping function of type @var{T} for a system of @var{dim}
dimensions. Please note that if you use a stepper method that
requires access to a driver object, it is advisable to use a driver
allocation method, which automatically allocates a stepper, too.
@end deftypefun
@deftypefun int gsl_odeiv2_step_reset (gsl_odeiv2_step * @var{s})
This function resets the stepping function @var{s}. It should be used
whenever the next use of @var{s} will not be a continuation of a
previous step.
@end deftypefun
@deftypefun void gsl_odeiv2_step_free (gsl_odeiv2_step * @var{s})
This function frees all the memory associated with the stepping function
@var{s}.
@end deftypefun
@deftypefun {const char *} gsl_odeiv2_step_name (const gsl_odeiv2_step * @var{s})
This function returns a pointer to the name of the stepping function.
For example,
@example
printf ("step method is '%s'\n",
gsl_odeiv2_step_name (s));
@end example
@noindent
would print something like @code{step method is 'rkf45'}.
@end deftypefun
@deftypefun {unsigned int} gsl_odeiv2_step_order (const gsl_odeiv2_step * @var{s})
This function returns the order of the stepping function on the previous
step. The order can vary if the stepping function itself is adaptive.
@end deftypefun
@deftypefun int gsl_odeiv2_step_set_driver (gsl_odeiv2_step * @var{s}, const gsl_odeiv2_driver * @var{d})
This function sets a pointer of the driver object @var{d} for stepper
@var{s}, to allow the stepper to access control (and evolve) object
through the driver object. This is a requirement for some steppers, to
get the desired error level for internal iteration of
stepper. Allocation of a driver object calls this function
automatically.
@end deftypefun
@deftypefun int gsl_odeiv2_step_apply (gsl_odeiv2_step * @var{s}, double @var{t}, double @var{h}, double @var{y}[], double @var{yerr}[], const double @var{dydt_in}[], double @var{dydt_out}[], const gsl_odeiv2_system * @var{sys})
This function applies the stepping function @var{s} to the system of
equations defined by @var{sys}, using the step-size @var{h} to advance
the system from time @var{t} and state @var{y} to time @var{t}+@var{h}.
The new state of the system is stored in @var{y} on output, with an
estimate of the absolute error in each component stored in @var{yerr}.
If the argument @var{dydt_in} is not null it should point an array
containing the derivatives for the system at time @var{t} on input. This
is optional as the derivatives will be computed internally if they are
not provided, but allows the reuse of existing derivative information.
On output the new derivatives of the system at time @var{t}+@var{h} will
be stored in @var{dydt_out} if it is not null.
The stepping function returns @code{GSL_FAILURE} if it is unable to
compute the requested step. Also, if the user-supplied functions
defined in the system @var{sys} return a status other than
@code{GSL_SUCCESS} the step will be aborted. In that case, the
elements of @var{y} will be restored to their pre-step values and the
error code from the user-supplied function will be returned. Failure
may be due to a singularity in the system or too large step-size
@var{h}. In that case the step should be attempted again with a
smaller step-size, e.g. @math{@var{h}/2}.
If the driver object is not appropriately set via
@code{gsl_odeiv2_step_set_driver} for those steppers that need it, the
stepping function returns @code{GSL_EFAULT}. If the user-supplied
functions defined in the system @var{sys} returns @code{GSL_EBADFUNC},
the function returns immediately with the same return code. In this
case the user must call @code{gsl_odeiv2_step_reset} before calling
this function again.
@end deftypefun
The following algorithms are available,
@deffn {Step Type} gsl_odeiv2_step_rk2
@cindex RK2, Runge-Kutta method
@cindex Runge-Kutta methods, ordinary differential equations
Explicit embedded Runge-Kutta (2, 3) method.
@end deffn
@deffn {Step Type} gsl_odeiv2_step_rk4
@cindex RK4, Runge-Kutta method
Explicit 4th order (classical) Runge-Kutta. Error estimation is
carried out by the step doubling method. For more efficient estimate
of the error, use the embedded methods described below.
@end deffn
@deffn {Step Type} gsl_odeiv2_step_rkf45
@cindex Fehlberg method, differential equations
@cindex RKF45, Runge-Kutta-Fehlberg method
Explicit embedded Runge-Kutta-Fehlberg (4, 5) method. This method is
a good general-purpose integrator.
@end deffn
@deffn {Step Type} gsl_odeiv2_step_rkck
@cindex Runge-Kutta Cash-Karp method
@cindex Cash-Karp, Runge-Kutta method
Explicit embedded Runge-Kutta Cash-Karp (4, 5) method.
@end deffn
@deffn {Step Type} gsl_odeiv2_step_rk8pd
@cindex Runge-Kutta Prince-Dormand method
@cindex Prince-Dormand, Runge-Kutta method
Explicit embedded Runge-Kutta Prince-Dormand (8, 9) method.
@end deffn
@deffn {Step Type} gsl_odeiv2_step_rk1imp
@cindex Implicit Euler method
Implicit Gaussian first order Runge-Kutta. Also known as implicit
Euler or backward Euler method. Error estimation is carried out by the
step doubling method. This algorithm requires the Jacobian and
access to the driver object via @code{gsl_odeiv2_step_set_driver}.
@end deffn
@deffn {Step Type} gsl_odeiv2_step_rk2imp
@cindex Implicit Runge-Kutta method
Implicit Gaussian second order Runge-Kutta. Also known as implicit
mid-point rule. Error estimation is carried out by the step doubling
method. This stepper requires the Jacobian and access to the driver
object via @code{gsl_odeiv2_step_set_driver}.
@end deffn
@deffn {Step Type} gsl_odeiv2_step_rk4imp
Implicit Gaussian 4th order Runge-Kutta. Error estimation is carried
out by the step doubling method. This algorithm requires the Jacobian
and access to the driver object via @code{gsl_odeiv2_step_set_driver}.
@end deffn
@deffn {Step Type} gsl_odeiv2_step_bsimp
@cindex Bulirsch-Stoer method
@cindex Bader and Deuflhard, Bulirsch-Stoer method.
@cindex Deuflhard and Bader, Bulirsch-Stoer method.
Implicit Bulirsch-Stoer method of Bader and Deuflhard. The method is
generally suitable for stiff problems. This stepper requires the
Jacobian.
@end deffn
@deffn {Step Type} gsl_odeiv2_step_msadams
@cindex Adams method
@cindex multistep methods, ODEs
@cindex predictor-corrector method, ODEs
@cindex Nordsieck form
A variable-coefficient linear multistep Adams method in Nordsieck
form. This stepper uses explicit Adams-Bashforth (predictor) and
implicit Adams-Moulton (corrector) methods in @math{P(EC)^m}
functional iteration mode. Method order varies dynamically between 1
and 12. This stepper requires the access to the driver object via
@code{gsl_odeiv2_step_set_driver}.
@end deffn
@deffn {Step Type} gsl_odeiv2_step_msbdf
@cindex BDF method
A variable-coefficient linear multistep backward differentiation
formula (BDF) method in Nordsieck form. This stepper uses the explicit
BDF formula as predictor and implicit BDF formula as corrector. A
modified Newton iteration method is used to solve the system of
non-linear equations. Method order varies dynamically between 1 and
5. The method is generally suitable for stiff problems. This stepper
requires the Jacobian and the access to the driver object via
@code{gsl_odeiv2_step_set_driver}.
@end deffn
@node Adaptive Step-size Control
@section Adaptive Step-size Control
@cindex Adaptive step-size control, differential equations
The control function examines the proposed change to the solution
produced by a stepping function and attempts to determine the optimal
step-size for a user-specified level of error.
@deftypefun {gsl_odeiv2_control *} gsl_odeiv2_control_standard_new (double @var{eps_abs}, double @var{eps_rel}, double @var{a_y}, double @var{a_dydt})
@tindex gsl_odeiv2_control
@tindex gsl_odeiv2_control_type
The standard control object is a four parameter heuristic based on
absolute and relative errors @var{eps_abs} and @var{eps_rel}, and
scaling factors @var{a_y} and @var{a_dydt} for the system state
@math{y(t)} and derivatives @math{y'(t)} respectively.
The step-size adjustment procedure for this method begins by computing
the desired error level @math{D_i} for each component,
@tex
\beforedisplay
$$
D_i = \epsilon_{abs} + \epsilon_{rel} * (a_{y} |y_i| + a_{dydt} h |y\prime_i|)
$$
\afterdisplay
@end tex
@ifinfo
@example
D_i = eps_abs + eps_rel * (a_y |y_i| + a_dydt h |y\prime_i|)
@end example
@end ifinfo
@noindent
and comparing it with the observed error @math{E_i = |yerr_i|}. If the
observed error @var{E} exceeds the desired error level @var{D} by more
than 10% for any component then the method reduces the step-size by an
appropriate factor,
@tex
\beforedisplay
$$
h_{new} = h_{old} * S * (E/D)^{-1/q}
$$
\afterdisplay
@end tex
@ifinfo
@example
h_new = h_old * S * (E/D)^(-1/q)
@end example
@end ifinfo
@noindent
where @math{q} is the consistency order of the method (e.g. @math{q=4} for
4(5) embedded RK), and @math{S} is a safety factor of 0.9. The ratio
@math{E/D} is taken to be the maximum of the ratios
@math{E_i/D_i}.
If the observed error @math{E} is less than 50% of the desired error
level @var{D} for the maximum ratio @math{E_i/D_i} then the algorithm
takes the opportunity to increase the step-size to bring the error in
line with the desired level,
@tex
\beforedisplay
$$
h_{new} = h_{old} * S * (E/D)^{-1/(q+1)}
$$
\afterdisplay
@end tex
@ifinfo
@example
h_new = h_old * S * (E/D)^(-1/(q+1))
@end example
@end ifinfo
@noindent
This encompasses all the standard error scaling methods. To avoid
uncontrolled changes in the stepsize, the overall scaling factor is
limited to the range @math{1/5} to 5.
@end deftypefun
@deftypefun {gsl_odeiv2_control *} gsl_odeiv2_control_y_new (double @var{eps_abs}, double @var{eps_rel})
This function creates a new control object which will keep the local
error on each step within an absolute error of @var{eps_abs} and
relative error of @var{eps_rel} with respect to the solution @math{y_i(t)}.
This is equivalent to the standard control object with @var{a_y}=1 and
@var{a_dydt}=0.
@end deftypefun
@deftypefun {gsl_odeiv2_control *} gsl_odeiv2_control_yp_new (double @var{eps_abs}, double @var{eps_rel})
This function creates a new control object which will keep the local
error on each step within an absolute error of @var{eps_abs} and
relative error of @var{eps_rel} with respect to the derivatives of the
solution @math{y'_i(t)}. This is equivalent to the standard control
object with @var{a_y}=0 and @var{a_dydt}=1.
@end deftypefun
@deftypefun {gsl_odeiv2_control *} gsl_odeiv2_control_scaled_new (double @var{eps_abs}, double @var{eps_rel}, double @var{a_y}, double @var{a_dydt}, const double @var{scale_abs}[], size_t @var{dim})
This function creates a new control object which uses the same algorithm
as @code{gsl_odeiv2_control_standard_new} but with an absolute error
which is scaled for each component by the array @var{scale_abs}.
The formula for @math{D_i} for this control object is,
@tex
\beforedisplay
$$
D_i = \epsilon_{abs} s_i + \epsilon_{rel} * (a_{y} |y_i| + a_{dydt} h |y\prime_i|)
$$
\afterdisplay
@end tex
@ifinfo
@example
D_i = eps_abs * s_i + eps_rel * (a_y |y_i| + a_dydt h |y\prime_i|)
@end example
@end ifinfo
@noindent
where @math{s_i} is the @math{i}-th component of the array @var{scale_abs}.
The same error control heuristic is used by the Matlab @sc{ode} suite.
@end deftypefun
@deftypefun {gsl_odeiv2_control *} gsl_odeiv2_control_alloc (const gsl_odeiv2_control_type * @var{T})
This function returns a pointer to a newly allocated instance of a
control function of type @var{T}. This function is only needed for
defining new types of control functions. For most purposes the standard
control functions described above should be sufficient.
@end deftypefun
@deftypefun int gsl_odeiv2_control_init (gsl_odeiv2_control * @var{c}, double @var{eps_abs}, double @var{eps_rel}, double @var{a_y}, double @var{a_dydt})
This function initializes the control function @var{c} with the
parameters @var{eps_abs} (absolute error), @var{eps_rel} (relative
error), @var{a_y} (scaling factor for y) and @var{a_dydt} (scaling
factor for derivatives).
@end deftypefun
@deftypefun void gsl_odeiv2_control_free (gsl_odeiv2_control * @var{c})
This function frees all the memory associated with the control function
@var{c}.
@end deftypefun
@deftypefun int gsl_odeiv2_control_hadjust (gsl_odeiv2_control * @var{c}, gsl_odeiv2_step * @var{s}, const double @var{y}[], const double @var{yerr}[], const double @var{dydt}[], double * @var{h})
This function adjusts the step-size @var{h} using the control function
@var{c}, and the current values of @var{y}, @var{yerr} and @var{dydt}.
The stepping function @var{step} is also needed to determine the order
of the method. If the error in the y-values @var{yerr} is found to be
too large then the step-size @var{h} is reduced and the function returns
@code{GSL_ODEIV_HADJ_DEC}. If the error is sufficiently small then
@var{h} may be increased and @code{GSL_ODEIV_HADJ_INC} is returned. The
function returns @code{GSL_ODEIV_HADJ_NIL} if the step-size is
unchanged. The goal of the function is to estimate the largest
step-size which satisfies the user-specified accuracy requirements for
the current point.
@end deftypefun
@deftypefun {const char *} gsl_odeiv2_control_name (const gsl_odeiv2_control * @var{c})
This function returns a pointer to the name of the control function.
For example,
@example
printf ("control method is '%s'\n",
gsl_odeiv2_control_name (c));
@end example
@noindent
would print something like @code{control method is 'standard'}
@end deftypefun
@deftypefun int gsl_odeiv2_control_errlevel (gsl_odeiv2_control * @var{c}, const double @var{y}, const double @var{dydt}, const double @var{h}, const size_t @var{ind}, double * @var{errlev})
This function calculates the desired error level of the @var{ind}-th component to @var{errlev}. It requires the value (@var{y}) and value of the derivative (@var{dydt}) of the component, and the current step size @var{h}.
@end deftypefun
@deftypefun int gsl_odeiv2_control_set_driver (gsl_odeiv2_control * @var{c}, const gsl_odeiv2_driver * @var{d})
This function sets a pointer of the driver object @var{d} for control
object @var{c}.
@end deftypefun
@node Evolution
@section Evolution
The evolution function combines the results of a stepping function and
control function to reliably advance the solution forward one step
using an acceptable step-size.
@deftypefun {gsl_odeiv2_evolve *} gsl_odeiv2_evolve_alloc (size_t @var{dim})
@tindex gsl_odeiv2_evolve
This function returns a pointer to a newly allocated instance of an
evolution function for a system of @var{dim} dimensions.
@end deftypefun
@deftypefun int gsl_odeiv2_evolve_apply (gsl_odeiv2_evolve * @var{e}, gsl_odeiv2_control * @var{con}, gsl_odeiv2_step * @var{step}, const gsl_odeiv2_system * @var{sys}, double * @var{t}, double @var{t1}, double * @var{h}, double @var{y}[])
This function advances the system (@var{e}, @var{sys}) from time
@var{t} and position @var{y} using the stepping function @var{step}.
The new time and position are stored in @var{t} and @var{y} on output.
The initial step-size is taken as @var{h}. The control function
@var{con} is applied to check whether the local error estimated by the
stepping function @var{step} using step-size @var{h} exceeds the
required error tolerance. If the error is too high, the step is
retried by calling @var{step} with a decreased step-size. This process
is continued until an acceptable step-size is found. An estimate of
the local error for the step can be obtained from the components of
the array @code{@var{e}->yerr[]}.
If the user-supplied functions defined in the system @var{sys} returns
@code{GSL_EBADFUNC}, the function returns immediately with the same
return code. In this case the user must call
@code{gsl_odeiv2_step_reset} and
@code{gsl_odeiv2_evolve_reset} before calling this function again.
Otherwise, if the user-supplied functions defined in the system
@var{sys} or the stepping function @var{step} return a status other
than @code{GSL_SUCCESS}, the step is retried with a decreased
step-size. If the step-size decreases below machine precision, a
status of @code{GSL_FAILURE} is returned if the user functions
returned @code{GSL_SUCCESS}. Otherwise the value returned by user
function is returned. If no acceptable step can be made, @var{t} and
@var{y} will be restored to their pre-step values and @var{h} contains
the final attempted step-size.
If the step is successful the function returns a suggested step-size
for the next step in @var{h}. The maximum time @var{t1} is guaranteed
not to be exceeded by the time-step. On the final time-step the value
of @var{t} will be set to @var{t1} exactly.
@end deftypefun
@deftypefun int gsl_odeiv2_evolve_apply_fixed_step (gsl_odeiv2_evolve * @var{e}, gsl_odeiv2_control * @var{con}, gsl_odeiv2_step * @var{step}, const gsl_odeiv2_system * @var{sys}, double * @var{t}, const double @var{h}, double @var{y}[])
This function advances the ODE-system (@var{e}, @var{sys}, @var{con})
from time @var{t} and position @var{y} using the stepping function
@var{step} by a specified step size @var{h}. If the local error
estimated by the stepping function exceeds the desired error level,
the step is not taken and the function returns
@code{GSL_FAILURE}. Otherwise the value returned by user function is
returned.
@end deftypefun
@deftypefun int gsl_odeiv2_evolve_reset (gsl_odeiv2_evolve * @var{e})
This function resets the evolution function @var{e}. It should be used
whenever the next use of @var{e} will not be a continuation of a
previous step.
@end deftypefun
@deftypefun void gsl_odeiv2_evolve_free (gsl_odeiv2_evolve * @var{e})
This function frees all the memory associated with the evolution function
@var{e}.
@end deftypefun
@deftypefun int gsl_odeiv2_evolve_set_driver (gsl_odeiv2_evolve * @var{e}, const gsl_odeiv2_driver * @var{d})
This function sets a pointer of the driver object @var{d} for evolve
object @var{e}.
@end deftypefun
@cindex discontinuities, in ODE systems
If a system has discontinuous changes in the derivatives at known
points, it is advisable to evolve the system between each discontinuity
in sequence. For example, if a step-change in an external driving
force occurs at times @math{t_a, t_b} and @math{t_c} then evolution
should be carried out over the ranges @math{(t_0,t_a)},
@math{(t_a,t_b)}, @math{(t_b,t_c)}, and @math{(t_c,t_1)} separately
and not directly over the range @math{(t_0,t_1)}.
@node Driver
@section Driver
The driver object is a high level wrapper that combines the evolution,
control and stepper objects for easy use.
@deftypefun {gsl_odeiv2_driver *} gsl_odeiv2_driver_alloc_y_new (const gsl_odeiv2_system * @var{sys}, const gsl_odeiv2_step_type * @var{T}, const double @var{hstart}, const double @var{epsabs}, const double @var{epsrel})
@deftypefunx {gsl_odeiv2_driver *} gsl_odeiv2_driver_alloc_yp_new (const gsl_odeiv2_system * @var{sys}, const gsl_odeiv2_step_type * @var{T}, const double @var{hstart}, const double @var{epsabs}, const double @var{epsrel})
@deftypefunx {gsl_odeiv2_driver *} gsl_odeiv2_driver_alloc_standard_new (const gsl_odeiv2_system * @var{sys}, const gsl_odeiv2_step_type * @var{T}, const double @var{hstart}, const double @var{epsabs}, const double @var{epsrel}, const double @var{a_y}, const double @var{a_dydt})
@deftypefunx {gsl_odeiv2_driver *} gsl_odeiv2_driver_alloc_scaled_new (const gsl_odeiv2_system * @var{sys}, const gsl_odeiv2_step_type * @var{T}, const double @var{hstart}, const double @var{epsabs}, const double @var{epsrel}, const double @var{a_y}, const double @var{a_dydt}, const double @var{scale_abs}[])
These functions return a pointer to a newly allocated instance of a
driver object. The functions automatically allocate and initialise the
evolve, control and stepper objects for ODE system @var{sys} using
stepper type @var{T}. The initial step size is given in
@var{hstart}. The rest of the arguments follow the syntax and
semantics of the control functions with same name
(@code{gsl_odeiv2_control_*_new}).
@end deftypefun
@deftypefun {int} gsl_odeiv2_driver_set_hmin (gsl_odeiv2_driver * @var{d}, const double @var{hmin})
The function sets a minimum for allowed step size @var{hmin} for
driver @var{d}. Default value is 0.
@end deftypefun
@deftypefun {int} gsl_odeiv2_driver_set_hmax (gsl_odeiv2_driver * @var{d}, const double @var{hmax})
The function sets a maximum for allowed step size @var{hmax} for
driver @var{d}. Default value is @code{GSL_DBL_MAX}.
@end deftypefun
@deftypefun {int} gsl_odeiv2_driver_set_nmax (gsl_odeiv2_driver * @var{d}, const unsigned long int @var{nmax})
The function sets a maximum for allowed number of steps @var{nmax} for
driver @var{d}. Default value of 0 sets no limit for steps.
@end deftypefun
@deftypefun {int} gsl_odeiv2_driver_apply (gsl_odeiv2_driver * @var{d}, double * @var{t}, const double @var{t1}, double @var{y}[])
This function evolves the driver system @var{d} from @var{t} to
@var{t1}. Initially vector @var{y} should contain the values of
dependent variables at point @var{t}. If the function is unable to
complete the calculation, an error code from
@code{gsl_odeiv2_evolve_apply} is returned, and @var{t} and @var{y}
contain the values from last successful step.
If maximum number of steps is reached, a value of @code{GSL_EMAXITER}
is returned. If the step size drops below minimum value, the function
returns with @code{GSL_ENOPROG}. If the user-supplied functions
defined in the system @var{sys} returns @code{GSL_EBADFUNC}, the
function returns immediately with the same return code. In this case
the user must call @code{gsl_odeiv2_driver_reset} before calling this
function again.
@end deftypefun
@deftypefun {int} gsl_odeiv2_driver_apply_fixed_step (gsl_odeiv2_driver * @var{d}, double * @var{t}, const double @var{h}, const unsigned long int @var{n}, double @var{y}[])
This function evolves the driver system @var{d} from @var{t} with
@var{n} steps of size @var{h}. If the function is unable to complete
the calculation, an error code from
@code{gsl_odeiv2_evolve_apply_fixed_step} is returned, and @var{t} and
@var{y} contain the values from last successful step.
@end deftypefun
@deftypefun {int} gsl_odeiv2_driver_reset (gsl_odeiv2_driver * @var{d})
This function resets the evolution and stepper objects.
@end deftypefun
@deftypefun {int} gsl_odeiv2_driver_reset_hstart (gsl_odeiv2_driver * @var{d}, const double @var{hstart})
The routine resets the evolution and stepper objects and sets new
initial step size to @var{hstart}. This function can be used e.g. to
change the direction of integration.
@end deftypefun
@deftypefun {int} gsl_odeiv2_driver_free (gsl_odeiv2_driver * @var{d})
This function frees the driver object, and the related evolution,
stepper and control objects.
@end deftypefun
@node ODE Example programs
@section Examples
@cindex Van der Pol oscillator, example
The following program solves the second-order nonlinear Van der Pol
oscillator equation,
@tex
\beforedisplay
$$
u''(t) + \mu u'(t) (u(t)^2 - 1) + u(t) = 0
$$
\afterdisplay
@end tex
@ifinfo
@example
u''(t) + \mu u'(t) (u(t)^2 - 1) + u(t) = 0
@end example
@end ifinfo
@noindent
This can be converted into a first order system suitable for use with
the routines described in this chapter by introducing a separate
variable for the velocity, @math{v = u'(t)},
@tex
\beforedisplay
$$
\eqalign{
u' &= v\cr
v' &= -u + \mu v (1-u^2)
}
$$
\afterdisplay
@end tex
@ifinfo
@example
u' = v
v' = -u + \mu v (1-u^2)
@end example
@end ifinfo
@noindent
The program begins by defining functions for these derivatives and
their Jacobian. The main function uses driver level functions to solve
the problem. The program evolves the solution from @math{(u, v) = (1,
0)} at @math{t=0} to @math{t=100}. The step-size @math{h} is
automatically adjusted by the controller to maintain an absolute
accuracy of @c{$10^{-6}$}
@math{10^@{-6@}} in the function values @math{(u, v)}.
The loop in the example prints the solution at the points
@math{t_i = 1, 2, \dots, 100}.
@example
@verbatiminclude examples/ode-initval.c
@end example
@noindent
The user can work with the lower level functions directly, as in
the following example. In this case an intermediate result is printed
after each successful step instead of equidistant time points.
@example
@verbatiminclude examples/ode-initval-low-level.c
@end example
@noindent
For functions with multiple parameters, the appropriate information
can be passed in through the @var{params} argument in
@code{gsl_odeiv2_system} definition (@var{mu} in this example) by using
a pointer to a struct.
@iftex
@sp 1
@center @image{vdp,3.4in}
@center Numerical solution of the Van der Pol oscillator equation
@center using Prince-Dormand 8th order Runge-Kutta.
@end iftex
@noindent
It is also possible to work with a non-adaptive integrator, using only
the stepping function itself,
@code{gsl_odeiv2_driver_apply_fixed_step} or
@code{gsl_odeiv2_evolve_apply_fixed_step}. The following program uses
the driver level function, with fourth-order
Runge-Kutta stepping function with a fixed stepsize of
0.001.
@example
@verbatiminclude examples/odefixed.c
@end example
@node ODE References and Further Reading
@section References and Further Reading
@itemize @w{}
@item
Ascher, U.M., Petzold, L.R., @cite{Computer Methods for Ordinary
Differential and Differential-Algebraic Equations}, SIAM,
Philadelphia, 1998.
@end itemize
@itemize @w{}
@item
Hairer, E., Norsett, S. P., Wanner, G., @cite{Solving Ordinary Differential
Equations I: Nonstiff Problems}, Springer, Berlin, 1993.
@end itemize
@itemize @w{}
@item
Hairer, E., Wanner, G., @cite{Solving Ordinary Differential
Equations II: Stiff and Differential-Algebraic Problems},
Springer, Berlin, 1996.
@end itemize
Many of the basic Runge-Kutta formulas can be found in the Handbook of
Mathematical Functions,
@itemize @w{}
@item
Abramowitz & Stegun (eds.), @cite{Handbook of Mathematical Functions},
Section 25.5.
@end itemize
@noindent
The implicit Bulirsch-Stoer algorithm @code{bsimp} is described in the
following paper,
@itemize @w{}
@item
G. Bader and P. Deuflhard, ``A Semi-Implicit Mid-Point Rule for Stiff
Systems of Ordinary Differential Equations.'', Numer.@: Math.@: 41, 373--398,
1983.
@end itemize
@noindent
The Adams and BDF multistep methods @code{msadams} and @code{msbdf}
are based on the following articles,
@itemize @w{}
@item
G. D. Byrne and A. C. Hindmarsh, ``A Polyalgorithm for the
Numerical Solution of Ordinary Differential Equations.'',
ACM Trans. Math. Software, 1, 71--96, 1975.
@item
P. N. Brown, G. D. Byrne and A. C. Hindmarsh, ``VODE: A
Variable-coefficient ODE Solver.'', SIAM J. Sci. Stat. Comput. 10,
1038--1051, 1989.
@item
A. C. Hindmarsh, P. N. Brown, K. E. Grant, S. L. Lee, R. Serban,
D. E. Shumaker and C. S. Woodward, ``SUNDIALS: Suite of
Nonlinear and Differential/Algebraic Equation Solvers.'', ACM
Trans. Math. Software 31, 363--396, 2005.
@end itemize
|