# Solve this equation numerically using "NDSolve"?

Posted 10 months ago
931 Views
|
3 Replies
|
1 Total Likes
|
 Hello, I am trying to derive the equations of motino for a simple pendulum using the Euler-Lagrange Equation. This works very well until I try to solve the equation numerically using "NDSolve". The error code is: "Equation or list of equations expected instead of ...". Does someone has an idea? Remove[L, g, M, Lagrange, T, V, eq, sol] x = L*Sin[\[Theta][t]]; y = -L*Cos[\[Theta][t]]; x' = D[x, t]; y' = D[y, t]; T = M/2*(x' + y')^2; V = M*g*y; Lagrange = T - V; eq = D[D[Lagrange, \[Theta]'], t] - D[Lagrange, \[Theta]]; L = 1; M = 1; g = 9.81; sol = NDSolve[{eq, \[Theta][0] == Pi, \[Theta]'[0] == 0}, \[Theta], {t, 0, 10}] 
3 Replies
Sort By:
Posted 10 months ago
 eq is not an equation. Try eq == 0 inside NDSolve In[16]:= Remove[L, g, M, Lagrange, T, V, eq, sol] x = L*Sin[\[Theta][t]]; y = -L*Cos[\[Theta][t]]; x' = D[x, t]; y' = D[y, t]; T = M/2*(x' + y')^2; V = M*g*y; Lagrange = T - V; eq = D[D[Lagrange, \[Theta]'], t] - D[Lagrange, \[Theta]]; L = 1; M = 1; g = 9.81; sol = NDSolve[{eq == 0, \[Theta][0] == Pi, \[Theta]'[0] == 0}, \[Theta], {t, 0, 10}] Out[28]= {{\[Theta] -> InterpolatingFunction[{{0., 10.}}, { 5, 7, 2, {13}, {4}, 0, 0, 0, 0, Automatic, {}, {}, False}, {{0., 0.0010264848819015065, 0.002052969763803013, 1.002052969763803, 2.002052969763803, 3.002052969763803, 4.0020529697638025, 5.0020529697638025, 6.0020529697638025, 7.0020529697638025, 8.002052969763803, 9.001026484881901, 10.}}, { DeveloperPackedArrayForm, {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39}, CompressedData[" 1:eJxTTMoPSmVkYGBQB2IJXZeQ34qcDgxoYFQcvzgAI98fLA== "]}, {Automatic}]}} 
 Thank you very much, that helped. If I may, I have one more question: When I now want to plot the result, I used: Plot[\[Theta], {t, 0, 10}] Nothing happened. What can be the error?
 I plotted your result using Plot[\[Theta][t] /. sol, {t, 0, 10}] It's constant, equal to Pi.