0

I want to get dy/dt from odeint of SciPy as well as y itself.

I understand that odeint gets the solution of dy/dt=func(y0,t). However, I also need to get dy/dt too.

I am dealing with a structural dynamic system in which:

y : displacement
dy/dt : velocity
d(dy/dt)/dt : acceleration (force)

And I put the system into two systems:

dy/dt = x
dx/dt = func(y0,x0,t)

Then, odeint(func, [y0's, x0's]) works perfectly. However, the final objective is to get the forces on the system.

Many thanks in advance^^

Raymond Hettinger
  • 216,523
  • 63
  • 388
  • 485

1 Answers1

0

Just to be sure I understand your problem correctly:

(d2x)/(dt2) = F(x,t)  // your second order system that you wish to solve, to simplify the problem I assume that dim(x) = 1

/* your system transformed to first order system of 2 equations
 * x[0] is your dx/dt (velocity), x[1] is your x (displacement)
 */

dxdt[1] = x[0];
dxdt[0] = F(x[1],t);

The results you will obtain are:

  • x[0] - velocity
  • x[1] - displacement
  • t - time

To calculate the acceleration you just have to do:

acc = F(x[1],t);

I hope that this is what you were asking for. Good luck.

pptaszni
  • 5,591
  • 5
  • 27
  • 43
  • It means that I have to execute the function evalution of F() one more time which is the most time-consuming process of my program. The real intention of my question was that I want to know how I can extract the function evaluation results from the process of odeint. As – Chris Kang Dec 02 '15 at 06:57
  • As you know, odeint has already done the function evaluation. My questiuon is how I can get the function evaluation results of odeint not to repeat the function evaluation by myself again. – Chris Kang Dec 02 '15 at 07:06
  • I am not sure if it is possible. You may of course add another state dxdt[2] = dF/dt (compute it analytically), but this will take even more time, because odeint may use various algorithms and the most popular is 6-point Runge-Kutta where function F is evaluated 6 times to compute the next sample.I think that odeint is designed in a way not to store the derivatives, because it will cost twice as much memory (the algorithm is not able to distinguish which one of your states is the important one). If speed is very important for you, try to write your own R-K implementation. – pptaszni Dec 02 '15 at 20:43