hi to everybody...i have this problem.....

this is my code:

Code:import numpy as np from numpy import * from pylab import * from scipy.integrate import ode import matplotlib.pyplot as plt import warnings u=([[],[],[],[],[],[],[],[],[],[],[]]) def molle(t,y): N = 1 x = u0.flatten()[0:3:6] y = u0.flatten()[1:3:6] z = u0.flatten()[2:3:6] vx = u0.flatten()[7 + 0:3:12] vy = u0.flatten()[7 + 1:3:12] vz = u0.flatten()[7 + 2:3:12] for i in range(0,N): Fx = 0 Fy = 0 Fz = 0 for j in range(0,N): if A[i, j] != 0: d = ([(x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2 + (z[i] - z[j]) ** 2]) ** 0.5 Fx = Fx + k[i, j] * (abs(x[j] - x[i]) - l[i, j]) * (x[j] - x[i]) * A[i, j] / d Fy = Fy + k[i, j] * (abs(y[j] - y[i]) - l[i, j]) * (y[j] - y[i]) * A[i, j] / d Fz = Fz + k[i, j] * (abs(z[j] - z[i]) - l[i, j]) * (z[j] - z[i]) * A[i, j] / d u[0 + 2 * (i-1)] = u0[2 * N + 0 + 2 * (i-1)] # dx u[1 + 2 * (i-1)] = u0[2 * N + 1 + 2 * (i-1)] # dy u[2 + 2 * (i-1)] = u0[2 * N + 2 + 2 * (i-1)] # dz u[2 * N + 0 + 2 * (i-1)] = Fx / m[i] # ax=F/m u[2 * N + 1 + 2 * (i-1)] = Fy / m[i] # ay=F/m u[2 * N + 2 + 2 * (i-1)] = Fz / m[i] # az=F/m return u x0 = array([-1, 1]) y0 = array([0, 0]) z0 = array([0, 0]) Vx0 = array([1, 0]) Vy0 = array([0, 0]) Vz0 = array([0, 0]) A =array([[0,1],[1,0]]) print A l = A k = A m = array([1, 1]) u0=array([[x0[0]],[x0[1]],[y0[0]],[y0[1]],[z0[1]],[z0[1]],[Vx0[0]],[Vx0[1]],[Vy0[0]],[Vy0[1]],[Vz0[0]],[Vz0[1]]]) # Create the time samples for the output of the ODE solver. # I use a large number of points, only because I want to make # a plot of the solution that looks nice. t0 = 0 t1 = 10 #backend = 'vode' backend = 'dopri5' #backend = 'dop853' solver = ode(molle).set_integrator(backend, nsteps=1) solver.set_initial_value(u0, t0) # suppress Fortran-printed warning solver._integrator.iwork[2] = -1 sol = [] warnings.filterwarnings("ignore", category=UserWarning) while solver.t < t1: solver.integrate(t1, step=True) sol.append([solver.t, solver.y]) warnings.resetwarnings() sol = np.array(sol) plt.plot(sol[:,0], sol[:,1], 'b.-') plt.show()

and this is the problem:

Traceback (most recent call last):

File "C:\Python27\Francesco\test.py", line 77, in <module>

solver.integrate(t1, step=True)

File "C:\Python27\lib\site-packages\scipy\integrate\_ode.py", line 386, in integrate

self.f_params, self.jac_params)

File "C:\Python27\lib\site-packages\scipy\integrate\_ode.py", line 888, in run

tuple(self.call_args) + (f_params,)))

ValueError: setting an array element with a sequence.

can anyone modify correctly my code?

Tweet This+ 1 thisPost To Linkedin