Numerically Solving non-linear pendulum differential equation [closed] I would like to numerically solve the following equation.

y''[x] == -(g/l) Sin[x]

I have tried the following code.

NDSolve[y''[x] == -(g/l) Sin[x], u, {x, 0, 2pi}]

I'm not sure what the u is supposed to mean. I also get an error for the 2pi.

closed as off-topic by Daniel Lichtblau, m_goldberg, Henrik Schumacher, C. E., MarcoBJan 28 '18 at 5:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Daniel Lichtblau, m_goldberg, Henrik Schumacher, C. E., MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

• 2pi is nothing in Mathematica. You want 2Pi. Capitalization matters. – b3m2a1 Jan 23 '18 at 5:28
• particle motion in 1D anharmonic well might be helpful. – Sumit Jan 23 '18 at 6:33

Numerical solution:

For a numerical solution you need to specify all the parameters, i.e., g, l. In Mathematica the correct syntax for pi is Pi. u should be replaced by the dependent variable y. Moreover, you also need to include initial/boundary conditions.

g = 1; l = 1;

sol = NDSolve[{y''[x] == -(g/l) Sin[x], y == 0, y' == 0}, y, {x, 0, 2*Pi}]

Plot[y[x] /. sol, {x, 0, 2*Pi}]

Analytical solution:

sol = First@DSolve[{y''[x] == -(g/l) Sin[x], y == a, y' == b}, y[x], x]

Plot[y[x] /. sol /. {g -> 1, l -> 1, a -> 1, b -> 1}, {x, 0, 2*Pi}]

Note, once again I have chosen randoms values for parameters and initial conditions.

Edit:

The OP has modified his original equation,

g = 9.8; l = 0.22;

sol = NDSolve[{y''[x] == -(g/l) Sin[y[x]], y == 1, y' == 0}, y, {x, 0, 2*Pi}]

Plot[y[x] /. sol, {x, 0, 2*Pi}] • Thanks. Now would it be possible to come up with an equation that would approximate that differential equation with a function? – Omkar Vaidya Jan 23 '18 at 10:21
• I also expected the plot to oscillate, like a pendulum would – Omkar Vaidya Jan 23 '18 at 11:21
• Thanks again. However, I still get a graph that doesn't oscillate. Here's how someone did it in maple (see edited question). The non-linear pendulum should oscillate. – Omkar Vaidya Jan 23 '18 at 13:46
• Sorry, the equation is actually supposed to be x''=(g/l)sinx. Now I understand why it doesn't oscillate. I tried the following: sol = First@DSolve[{y''[x] == -(g/l) Sin[y], y == a, y' == b}, y[x], x] Plot[y[x] /. sol /. {g -> 1, l -> 1, a -> 1, b -> 1}, {y, 0, 2*Pi}] I still get an error. – Omkar Vaidya Jan 23 '18 at 14:04
• Try sol = NDSolve[{y''[x] == -(g/l) Sin[y[x]], y == 1, y' == 0}, y, {x, 0, 2*Pi}] – Sjoerd Smit Jan 23 '18 at 14:06