Message Boards Message Boards

0
|
5274 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Solve this equation numerically using "NDSolve"?

Posted 6 years ago

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}]
POSTED BY: Jonas Hamp
3 Replies

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.}}, {
    Developer`PackedArrayForm, {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 
     30, 33, 36, 39}, CompressedData["
1:eJxTTMoPSmVkYGBQB2IJXZeQ34qcDgxoYFQcvzgAI98fLA==
"]}, {Automatic}]}}
POSTED BY: Frank Kampas
Posted 6 years ago
POSTED BY: Jonas Hamp

I plotted your result using

Plot[\[Theta][t] /. sol, {t, 0, 10}]

It's constant, equal to Pi.

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract