Back to index

kdeartwork  4.3.2
Public Member Functions | Protected Member Functions | Private Attributes
PendulumOdeSolver Class Reference

ODE solver for the Pendulum equations. More...

#include <pendulum.h>

Inheritance diagram for PendulumOdeSolver:
Inheritance graph
[legend]
Collaboration diagram for PendulumOdeSolver:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PendulumOdeSolver (const double &t, const double &dt, const Vector4d &y, const double &eps, const double &m1, const double &m2, const double &l1, const double &l2, const double &g)
 Constuctor for the RK solver of the pendulum equation of motion.
void integrate (const double &dx)
 Integrates the ordinary differential equation from the current x value to x+dx.
const double & X (void) const
 Get current x value.
void X (const double &a)
 Set current x value.
const Matrix< double, D, 1 > & Y (void) const
 Get current y value.
void Y (const Matrix< double, D, 1 > &a)
 Set current y values.
const Matrix< double, D, 1 > & dYdX (void) const
 Get current dy/dx value.
const double & dX (void) const
 Get current estimated step size dX.
void dX (const double &a)
 Set estimated step size dX.
const double & Eps (void) const
 Get current presision.
void Eps (const double &a)
 Set estimated presision.

Protected Member Functions

Vector4d f (const double &x, const Vector4d &y) const
 ODE function for the pendulum equation of motion system.
virtual Matrix< double, D, 1 > f (const double &x, const Matrix< double, D, 1 > &y) const =0
 ODE function.

Private Attributes

const double m_A
 These private variables contain constants for faster numeric calculation.
const double m_B1
const double m_B
const double m_C
const double m_D
const double m_E
const double m_M

Detailed Description

ODE solver for the Pendulum equations.

Definition at line 50 of file pendulum.h.


Constructor & Destructor Documentation

PendulumOdeSolver::PendulumOdeSolver ( const double &  t,
const double &  dt,
const Vector4d &  y,
const double &  eps,
const double &  m1,
const double &  m2,
const double &  l1,
const double &  l2,
const double &  g 
)

Constuctor for the RK solver of the pendulum equation of motion.

Parameters:
tinitial time in seconds
dtinitial time increment in seconds, just a hint for solver
ygeneralized coordinates of pendulum system
epsrelative precision
m1mass of upper pendulum
m2mass of lower pendulum
l1length of upper pendulum
l2length of lower pendulum
ggravitational constant

Definition at line 100 of file pendulum.cpp.

   : RkOdeSolver<double,4>(t, y, dt, eps),
     // constants for faster numeric calculation, derived from m1,m2,l1,l2,g
     m_A(1.0/(m2*l1*l1)),
     m_B1(m2*l1*l2),
     m_B(1.0/m_B1),
     m_C((m1+m2)/(m2*m2*l2*l2)),
     m_D(g*(m1+m2)*l1),
     m_E(g*m2*l2),
     m_M((m1+m2)/m2)
{
}

Member Function Documentation

const double & RkOdeSolver< double , D >::dX ( void  ) const [inherited]

Get current estimated step size dX.

Returns:
Reference of dX value.
void RkOdeSolver< double , D >::dX ( const double &  a) [inherited]

Set estimated step size dX.

Parameters:
aThe value to be set.
const Matrix<double ,D,1>& RkOdeSolver< double , D >::dYdX ( void  ) const [inherited]

Get current dy/dx value.

Returns:
Reference of dy/dx vector.
const double & RkOdeSolver< double , D >::Eps ( void  ) const [inherited]

Get current presision.

Returns:
Reference of precision value.
void RkOdeSolver< double , D >::Eps ( const double &  a) [inherited]

Set estimated presision.

Parameters:
aThe value to be set.
Vector4d PendulumOdeSolver::f ( const double &  x,
const Vector4d &  y 
) const [protected]

ODE function for the pendulum equation of motion system.

Parameters:
xtime
ygeneralized coordinates of pendulum system
Returns:
derivation dy/dx

Definition at line 122 of file pendulum.cpp.

{
   (void)x; // unused

   const double& q1 = y[0];
   const double& q2 = y[1];
   const double& p1 = y[2];
   const double& p2 = y[3];

   const double cosDq = std::cos(q1-q2);
   const double iden  = 1.0/(m_M - cosDq*cosDq); // invers denominator
   const double dq1dt = (m_A*p1 - m_B*cosDq*p2)*iden;
   const double dq2dt = (m_C*p2 - m_B*cosDq*p1)*iden;

   Vector4d ypr;
   ypr[0] = dq1dt;
   ypr[1] = dq2dt;

   const double K = m_B1 * dq1dt*dq2dt * std::sin(q1-q2);
   ypr[2] = -K - m_D * std::sin(q1);
   ypr[3] =  K - m_E * std::sin(q2);

   return ypr;
}
virtual Matrix<double ,D,1> RkOdeSolver< double , D >::f ( const double &  x,
const Matrix< double , D, 1 > &  y 
) const [protected, pure virtual, inherited]

ODE function.

Parameters:
xIntegration value
yFunction value
Returns:
Derivation

This purely virtual function returns the value of dy/dx for the given parameter values of x and y. This function is integrated by the Runge-Kutta algorithm.

void RkOdeSolver< double , D >::integrate ( const double &  dx) [inherited]

Integrates the ordinary differential equation from the current x value to x+dx.

Parameters:
dxx-interval size to integrate over starting from x. dx may be negative.

The integration is performed by calling rkStepCheck() repeatedly until the desired x value is reached.

const double & RkOdeSolver< double , D >::X ( void  ) const [inherited]

Get current x value.

Returns:
Reference of x value.
void RkOdeSolver< double , D >::X ( const double &  a) [inherited]

Set current x value.

Parameters:
aThe value to be set.
const Matrix<double ,D,1>& RkOdeSolver< double , D >::Y ( void  ) const [inherited]

Get current y value.

Returns:
Reference of y vector.
void RkOdeSolver< double , D >::Y ( const Matrix< double , D, 1 > &  a) [inherited]

Set current y values.

Parameters:
aThe vector to be set.

Member Data Documentation

const double PendulumOdeSolver::m_A [private]

These private variables contain constants for faster numeric calculation.

They are derived from the constructor arguments m1,m2,l1,l2,g.

Definition at line 84 of file pendulum.h.

const double PendulumOdeSolver::m_B [private]

Definition at line 84 of file pendulum.h.

const double PendulumOdeSolver::m_B1 [private]

Definition at line 84 of file pendulum.h.

const double PendulumOdeSolver::m_C [private]

Definition at line 84 of file pendulum.h.

const double PendulumOdeSolver::m_D [private]

Definition at line 84 of file pendulum.h.

const double PendulumOdeSolver::m_E [private]

Definition at line 84 of file pendulum.h.

const double PendulumOdeSolver::m_M [private]

Definition at line 84 of file pendulum.h.


The documentation for this class was generated from the following files: