We are trying to run a python code to solve a coupled pendulum problem for university assignment. These pendulums are linked via a spring 'elastic band'. We have most of the code working and correct however we are having problems modelling the spring accurately.
We are looking at using an 'if' function to do this. As the spring is extended past resting length a force will be applied however when less than resting length it has no affect on the system.
We have tried to run the following if function.
if x_dx >= 0: Fk = c.k*dx #Force due to spring if equal or greater than resting length
else:
Fk = 0 #Force due to spring is less than resting length
The following error is given.
if x_dx >= 0: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
This is our function for the system.
def project(Z,c):
c = Constants()
theta_1 = Z[0]
thetadot_1 = Z[1]
theta_2 = Z[2]
thetadot_2 = Z[3]
b = np.arctan(c.a2*np.cos(theta_2)-c.a1*np.cos(theta_1)/c.w-c.a1*np.sin(theta_1)+c.a2*np.sin(theta_2))
dx = c.w-c.a1*np.sin(theta_1)+c.a2*np.sin(theta_2)/np.cos(b)-c.x
x_dx = c.w-c.a1*np.sin(theta_1)+c.a2*np.sin(theta_2)/np.cos(b)
alpha2 = theta_2+b
alpha1 = theta_1+b
I_P1 = (1/12)*c.m1*(c.H1**2+c.W1**2)+c.m1*c.l1**2
I_P2 = (1/12)*c.m2*(c.H2**2+c.W2**2)+c.m2*c.l2**2
if x_dx >= 0:
Fk = c.k*dx #Force due to spring if equal or greater than resting length
else:
Fk = 0 #Force due to spring is less than resting length
Fg1 = c.m1*c.g #Gravitational force on pendulum 1
Fg2 = c.m2*c.g #Gravitational force on pendulum 2
thetadotdot_1 = (1/I_P1)*(-c.l1*Fg1*np.sin(theta_1)+c.a1*Fk*np.cos(alpha1)) #Derived equation for pendulum 1 (See report for full derivation)
thetadotdot_2 = (1/I_P2)*(-c.l2*Fg2*np.sin(theta_2)-c.a2*Fk*np.cos(alpha2))
Zdot = [thetadot_1, thetadotdot_1, thetadot_2, thetadotdot_2]
return Zdot
Aucun commentaire:
Enregistrer un commentaire