Hi i'm trying to write in jupyter notebook a program to calculate and then animate a 3d double pendulum but i've run in many issues; first with the solution dict, i had to decompose it in simpler solution (Lagrangian system) and then group them. Then i tried to use lambdify to change the solution from symbolic to numerical, but i also run in another issue using odeint(..) basically there are still derivatives after lambdify... https://github.com/Riccardo-Venturi/gpt-help.git I have two versions but couldn't solve it, best version is the 3D without 22. @jared f, o are the angles, d(f,O)/dt, dd(f,O) / dt**2 they are the rate of change, you have 4 angles
sol_the1_dd = smp.solve(l1_O, O1_dd, dict=True, simplify=False, rational=False)
# Sostituisci la soluzione trovata in LE2 e risolvi per the2_dd
LE2_substituted = l2_O.subs(O1_dd, sol_the1_dd[0][O1_dd])
sol_the2_dd = smp.solve(LE2_substituted, O2_dd, dict=True, simplify=False, rational=False)
# Sostituisci la soluzione trovata in LE3 e risolvi per phi1_dd
LE3_substituted = l1_f.subs(O2_dd, sol_the2_dd[0][O2_dd])
sol_phi1_dd = smp.solve(LE3_substituted, f1_dd, dict=True, simplify=False, rational=False)
# Sostituisci la soluzione trovata in LE4 e risolvi per phi2_dd
LE4_substituted = l2_f.subs(f1_dd, sol_phi1_dd[0][f1_dd])
sol_phi2_dd = smp.solve(LE4_substituted, f2_dd, dict=True, simplify=False, rational=False)
# Visualizza le soluzioni parziali
#print(sol_the1_dd, sol_the2_dd, sol_phi1_dd, sol_phi2_dd)
combined_solutions = {**sol_the1_dd[0], **sol_the2_dd[0], **sol_phi1_dd[0], **sol_phi2_dd[0]}
print("Espressione per the1_dd:", combined_solutions[O1_dd])
print("Espressione per the2_dd:", combined_solutions[O2_dd])
print("Espressione per phi1_dd:", combined_solutions[f1_dd])
print("Espressione per phi2_dd:", combined_solutions[f2_dd])
Espressione per the1_dd: -g*m1*sin(\theta_1(t))/(m1*r1 + m2*r1) - g*m2*sin(\theta_1(t))/(m1*r1 + m2*r1) + m1*r1*sin(\theta_1(t))*cos(\theta_1(t))*Derivative(\phi_1(t), t)**2
I Tried this but doesn't work
from sympy import Derivative, Function,symbols
# Definizione delle variabili simboliche di funzione
t = symbols('t')
phi1 = Function('phi_1')(t)
phi2 = Function('phi_2')(t)
theta1 = Function('theta_1')(t)
theta2 = Function('theta_2')(t)
# Definizione delle derivate
phi1_d = Derivative(phi1, t)
phi2_dd = Derivative(phi2, t, t)
theta2_d = Derivative(theta2, t)
theta2_dd = Derivative(theta2, t, t)
# Ora puoi utilizzare queste definizioni nelle tue sostituzioni
simplified_the1_dd = combined_solutions[O1_dd].subs({
phi1_d: f1_d,
phi2_dd: f2_dd,
theta2_d: O2_d,
theta2_dd: O2_dd
})
# Semplificazione dell'espressione
simplified_the1_dd = smp.simplify(simplified_the1_dd)
# Sostituzioni delle derivate
simplified_the1_dd_substituted = simplified_the1_dd.subs({
Derivative(phi1, t): f1_d,
Derivative(phi2, t, t): f2_dd,
Derivative(theta2, t): O2_d,
Derivative(theta2, t, t): O2_dd
})
# Ulteriore semplificazione
i expected it to chabge the derivative with the variable function and then process it with lambdify to use it in a numerical solution but nothin