ameliorez ce code pour que thetadot soit la derivée de theta: from sympy import solve,…
- User
ameliorez ce code pour que theta_dot soit la derivée de theta: from sympy import solve, Matrix import sympy as sp #eqprint, MODULE DE CALCUL SYMBOLIQUE
Définition des variables et des paramètres
m, L, g,k = sp.symbols('m L g k') t = sp.symbols('t', real=True)
le NDDL
N=6
Définition des coordonnées généralisées et de leurs dérivées
theta=sp.symbols('theta1:%d' % (N+1)) theta=sp.diff(theta,t) theta_dot=sp.symbols('theta_dot1:%d' % (N+1))
Calcul de l'energie cinetique T
T_N=0 for i in range(1,N+1): T_N+=0.5mLLtheta_dot[i-1]**2
calcul de l' énergie potentielle U
U_N1=0 for i in range(1,N): U_N1+=0.5kLL(theta[i]-theta[i-1])**2 U_N2=0.5kLL(theta[0])**2+0.5kLL(theta[i-2])*2 U_N3=0 for i in range(1,N+1): U_N3+=mgL(1-sp.cos(theta[i-1])) #U_N= sp.Function('U')(*theta) U_N =U_N1+U_N2+U_N3
Calcul du lagrangien
L_N= T_N-U_N print(sp.latex(L_N))
Equations de mouvement Euler-lagrange
equations = [] for i in range(N): L_theta=sp.diff(L_N,theta[i]) L_theta_dot=sp.diff(L_N,theta_dot[i]) dL_theta_dot_dt=sp.diff(L_theta_dot,symbols('t'))
codeequation = sp.Eq(L_theta - dL_theta_dot_dt,0) equations.append(sp.expand(equation))print('EDM') print(' ') for i in range(N-1): print(equations[i]) print(' ')
- Assistant
from sympy import symbols, Eq, diff, cos, Function, Eq, expand, Latex
m, L, g, k = symbols('m L g k') t = symbols('t', real=True) N = 6
theta = symbols('theta1:%d' % (N+1)) theta_dot = symbols('theta_dot1:%d' % (N+1))
T_N = 0 for i in range(1, N+1): T_N += 0.5 * m * L * L * theta_dot[i-1]**2
U_N = 0 for i in range(1, N): U_N += 0.5 * k * L * L * (theta[i] - theta[i-1])**2 U_N += 0.5 * k * L * L * (theta[0])**2 + 0.5 * k * L * L * (theta[N-1])**2
for i in range(1, N+1): U_N += m * g * L * (1 - cos(theta[i-1]))
L_N = T_N - U_N print(Latex(L_N))
equations = [] for i in range(N): L_theta = diff(L_N, theta[i]) L_theta_dot = diff(L_N, theta_dot[i]) dL_theta_dot_dt = diff(L_theta_dot, t)
codeequation = Eq(L_theta - dL_theta_dot_dt, diff(theta_dot[i], t)) equations.append(expand(equation))print('Euler-Lagrange Equations') print() for i in range(N-1): print(equations[i]) print()