1

I have a problem with odeint. I have to solve an first order differential system and then a second order system but I am a little confused with the first order one. Can you explain what I have marked as wrong? Thank you :)

import scipy.integrate as integrate
import numpy as np
def fun(t,y):
  ys = np.array([y[1], (1-y[0]**2)*y[1]-y[0]])
  return(ys)
N = 3
x0 = np.array([2.00861986087484313650940188,0])
t0tf = [0, 17.0652165601579625588917206249]
T=([0 for i in range (N+1)])
T[0]= t0tf[0]
Pas = (t0tf[1]-t0tf[0])/N
for i in range (1,N+1):
       T[i]= t0tf[0] + i*Pas
X = integrate.odeint(fun, x0,T,Dfun=None, col_deriv=0,full_output=True)
T = np.array(T)
T = T.reshape(N+1,1)
S = np.append(X,T,axis=1)
print(S)

The returned error is:

ys = np.array([y[1], (1-y[0]**2)*y[1]-y[0]])

TypeError: 'float' object is not subscriptable

ali_m
  • 71,714
  • 23
  • 223
  • 298
Valentin Mercier
  • 385
  • 1
  • 4
  • 16
  • Have you had a look at http://stackoverflow.com/questions/27820725/how-to-solve-diff-eq-using-scipy-integrate-odeint ? The usage of `odeint` is explained quite extensively there. – jhoepken Mar 12 '16 at 10:39
  • yes i have already check but the fact is that i think i have a problem in the definition of my function but i can't find where is it... because this function work in my euler and runge-kutta algorithm – Valentin Mercier Mar 12 '16 at 10:54
  • thank you for the help on spelling, i still study english but i'm not good at all :p – Valentin Mercier Mar 12 '16 at 10:55
  • I suggest that you reduce your data structures to the ones in the working example and go from there. Try to run that one and adopt it to your problem, if you don't know what you are doing, just yet. – jhoepken Mar 12 '16 at 11:25

1 Answers1

0

You need to reverse the order of the arguments to your derivative function - it should be f(y, t), not f(t, y). This is the opposite order to that used by the scipy.integrate.ode class.

Also, the concatenation S = np.append(X,T,axis=1) will fail because X is a tuple containing your integrals and a dict. Use S = np.append(X[0],T,axis=1) instead.

ali_m
  • 71,714
  • 23
  • 223
  • 298
  • Thank you , i tried what you advice , it's work but i have a problem with the append... It make me an error like 'in above message, r1 = 0.0000000000000D+00 lsoda-- run aborted.. apparent infinite loop output[1]['message'] = _msgs[output[-1]] KeyError: 1' – Valentin Mercier Mar 12 '16 at 18:07
  • If I make the two changes mentioned in my answer, the code you posted in your question executes without a problem. What you're describing sounds like a completely different problem - I can't reproduce it with the information you've given so far. – ali_m Mar 12 '16 at 19:00
  • ok, before everything thank you for you help, i've found the problem is a bug of odeint which were corrected in the last version :) – Valentin Mercier Mar 12 '16 at 21:00