Beispiel #1
0
/** \brief Generate a simple ODE */
void simpleODE(FX& ffcn, double& tf, vector<double>& x0, double& u0){
  // Time 
  SXMatrix t = ssym("t");
  
  // Parameter
  SXMatrix u = ssym("u");
  
  // Differential states
  SXMatrix s = ssym("s"), v = ssym("v"), m = ssym("m");
  SXMatrix x;
  x.append(s);
  x.append(v);
  x.append(m); 
  
  // Constants
  double alpha = 0.05; // friction
  double beta = 0.1;   // fuel consumption rate
  
  // Differential equation
  SXMatrix ode;
  ode.append(v);
  ode.append((u-alpha*v*v)/m);
  ode.append(-beta*u*u); 
      
  // Quadrature
  SXMatrix quad = pow(v,3) + pow((3-sin(t))-u,2);

  // Callback function
  ffcn = SXFunction(daeIn("t",t,"x",x,"p",u),daeOut("ode",ode,"quad",quad));

  // End time
  tf = 0.5;

  // Initial value
  x0.resize(3);
  x0[0] = 0;
  x0[1] = 0;
  x0[2] = 1;
  
  // Parameter
  u0 = 0.4;
}