I am trying to input an random external perturbation (F) on the ODEs modeling a spring-mass-damper system, but I am not having success.
When I try a constant value for the perturbation (F=5), as in the following example, the code runs perfectly. But when I try to insert the random external perturbation that I calculate before the function (mydiff ), this message appears: "Setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part. "
def mydiff(x,t):
c=2 #damping
k=4 #stiffness
m=20 #mass
F=5 #constant value
dx1dt=x[1]
dx2dt=(F-c*x[1]-k*x[0])/m
dxdt=[dx1dt,dx2dt]
return dxdt
x=odeint(mydiff,x_ini,t)