In this section we will give an overview on simultaneous integration of ODEs and associated first order variational equations.
One step Taylor method
Class [L]DOdeSolver can also integrate first order variational equations of ODEs. Creating an instance of solver is exactly the same as in the case of computing the trajectory only (see section One-step Taylor method).
In order to compute derivatives with respect to initial conditions one has to
- specify initial conditions for the trajectory and for variational equations
- define matrix that will store solution to variational equations (monodromy matrix)
- call operator that simultaneously computes solution to IVP for ODE and first order variational equations
DVector y = solver(t,initPoint,initMatrix,D);
After the last instruction the vector y will contain approximate solution after specified time step and the matrix D will contain solution to the variational equations at the same time.
- Note
- Two arguments initMatrix and D can be the same object instance. This is used to obtain monodromy matrix after many steps of integration.
int dimension = ...;
for(int i=0;i<numberOfSteps;++i)
u = solver(t,u,D,D);
cout << "t=" << t << ", u=" << u << endl;
cout << "Monodromy matrix: " << D << endl;
}
static Matrix Identity(size_type dim)
Definition: Matrix.hpp:109
Complete example (from examples/odes/DSolverVariationalEquationsExample.cpp):
#include <cstdio>
DMap pendulum(
"time:t;par:omega;var:x,y;fun:y,sin(omega*t)-sin(x);");
pendulum.setParameter("omega",1.);
solver.setStep(0.125);
u[0] = 1.;
u[1] = 2.;
double t = 4;
do{
u = solver(t,u,D,D);
printf("t=%6f, x=%6f, y=%6f, du1/dx=%6f, du1/dy=%f6, du2/dx=%6f, du2/dy=%6f\n",t,u[0],u[1],D[0][0],D[0][1],D[1][0],D[1][1]);
}while(t<5);
return 0;
}
This class is used to represent a map .
Definition: Map.h:125
int main(int argc, char *argv[])
Definition: argdemo.cpp:81
int order
Definition: tayltst.cpp:31
Definition: ApplicationDesc.h:23
capd::dynsys::BasicOdeSolver< capd::DMap > DOdeSolver
Definition: typedefs.h:26
First order variational equations
The class [L]DTimeMap (see Long-time integration) provides interface for long-time integration of ODEs with associated variational equations (i.e. derivatives of solution with respect to initial condition). One has to specify initial conditions for both main equations and for variational equations
int dimension = ...;
double initTime = ...;
and call suitable operator
double finalTime = ...;
DMatrix monodromyMatrix(dimension,dimension);
DVector y = timeMap(finalTime,x,initMatrix,monodromyMatrix,initTime);
- Note
- When solving IVPs with variational equations the built in step control mechanism predicts time steps to fix requested error tolerances both for main equations and for variational equations.
- Note
- The argument initMatrix can be skipped. Then the initial condition for variational equations is set to identity.
DVector y = timeMap(finalTime,x,monodromyMatrix,initTime);
- Note
- The last argument initTime can be skipped. Then it is set to zero by default.
DVector y = timeMap(finalTime,x,monodromyMatrix);
Complete example (from examples/odes/DTimeMapVariationalEquationsExample.cpp):
#include <cstdio>
DMap pendulum(
"time:t;par:omega;var:x,dx;fun:dx,sin(omega*t)-sin(x);");
pendulum.setParameter("omega",1.);
u[0] = 1.;
u[1] = 2.;
double initTime = 4;
double finalTime = 8;
double data[] = {1,1,3,4};
u = timeMap(finalTime,u,initMatrix,D,initTime);
printf("t=%6f, x=%6f, y=%6f, du1/dx=%6f, du1/dy=%f6, du2/dx=%6f, du2/dy=%6f\n",finalTime,u[0],u[1],D[0][0],D[0][1],D[1][0],D[1][1]);
return 0;
}
TimeMap class provides methods for transport of sets (or points) by a given flow over some time inter...
Definition: TimeMap.h:34
Second order variational equations
The class [L]DC2TimeMap (see Long-time integration) provides interface for long-time integration of ODEs with associated first and second order variational equations. One has to specify initial conditions for main ODE and for first and second order variational equations.
int dimension = ...;
double initTime = ...;
capd::diffAlgebra::Hessian< capd::DVector::ScalarType, capd::DVector::csDim, capd::DMatrix::ColumnVectorType::csDim > DHessian
Definition: fdlib.h:40
and call suitable operator
double finalTime = ...;
DVector y = timeMap(finalTime,x,initMatrix,initHessian,D,H,initTime);
- Note
- When solving IVPs with variational equations the built in step control mechanism predicts time steps to fix requested error tolerances both for main equations and for first and second order variational equations.
- Note
- The arguments initMatrix and initHessian can be skipped. Then the initial condition for first order variational equations is set to identity and for the second order variational equations is set to zero.
DVector y = timeMap(finalTime,x,D,H,initTime);
- Note
- The last argument initTime can be skipped. Then it is set to zero by default.
DVector y = timeMap(finalTime,x,D,H);
Complete example (from examples/odes/DTimeMapHessianExample.cpp):
#include <cstdio>
DMap pendulum(
"time:t;par:omega;var:x,dx;fun:dx,sin(omega*t)-sin(x);");
pendulum.setParameter("omega",1.);
u[0] = 1.;
u[1] = 2.;
double initTime = 4;
double finalTime = 8;
double initDerData[] = {1,1,3,4};
double initHessData[] = {1,3,3,0,2,1};
DMatrix initMatrix(2,2,initDerData);
u = timeMap(finalTime,u,initMatrix,initHessian,D,H,initTime);
printf("t=%6f, x=%6f, y=%6f\n",finalTime,u[0],u[1]);
printf("du1/dx=%6f, du1/dy=%f6, du2/dx=%6f, du2/dy=%6f\n",D[0][0],D[0][1],D[1][0],D[1][1]);
printf(
"d2u1/dxdx=%6f, d2u1/dxdy=%f6, d2u1/dydy=%f6, d2u1/dxdx=%6f, d2u1/dxdy=%f6, d2u1/dydy=%f6\n",
H(0,0,0),H(0,0,1),H(0,1,1),H(1,0,0),H(1,0,1),H(1,1,1)
);
return 0;
}
capd::dynsys::BasicC2OdeSolver< capd::DMap > DC2OdeSolver
Definition: typedefs.h:27
Higher order variational equations
The class [L]DCnTimeMap (see Long-time integration) provides interface for long-time integration of ODEs with associated first, second and higher order variational equations. One has to specify initial conditions for main ODE and for all variational equations.
int dimension = ...;
double initTime = ...;
capd::diffAlgebra::Jet< capd::DMatrix, 0 > DJet
Definition: fdlib.h:44
and call one of overloaded operators
double finalTime = ...;
DJet J(dimension,degree);
DVector y1 = timeMap(finalTime,x,J,initTime);
DVector y2 = timeMap(finalTime,initJet,J,initTime);
- Note
- When solving IVPs with variational equations the built in step control mechanism predicts time steps to fix requested error tolerances both for main equations and for all variational equations up to requested degree.
- Note
- After call to the first version of operator
DVector y1 = timeMap(finalTime,x,J,initTime);
the initial condition for first order variational equations is set to identity. Higher order varational equations have initial conditions set to zero.
- Note
- After call to the second version of operator
DVector y1 = timeMap(finalTime,initJet,J,initTime);
the initial condition for the main equations and all variational equations are copied from the object initJet.
- Note
- In both cases the last argument initTime can be skipped. Then it is set to zero by default.
DVector y1 = timeMap(finalTime,x,J);
DVector y2 = timeMap(finalTime,initJet,J);
Complete example (from examples/odes/DTimeMapJetExample.cpp):
#include <iostream>
const int degree = 4;
DMap pendulum(
"time:t;par:omega;var:x,dx;fun:dx,sin(omega*t)-sin(x);",degree);
pendulum.setParameter("omega",1.);
double initTime = 4;
double finalTime = 8;
initJet(0) = 1; initJet(1) = 2;
initJet(0,0) = 1; initJet(0,1) = 1; initJet(1,0) = 3; initJet(1,1) = 4;
initJet(0,0,0) = 1; initJet(0,0,1) = 3; initJet(0,1,1) = 3; initJet(1,0,0) = 0; initJet(1,0,1) = 2; initJet(1,1,1) = 1;
timeMap(finalTime,initJet,J,initTime);
std::cout << J.toString() << std::endl;
return 0;
}
capd::dynsys::BasicCnOdeSolver< capd::DMap > DCnOdeSolver
Definition: typedefs.h:28