2
$\begingroup$

enter image description hereI 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.

$\endgroup$

closed as off-topic by Daniel Lichtblau, m_goldberg, Henrik Schumacher, C. E., MarcoB Jan 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.

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

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] == 0, y'[0] == 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[0] == a, y'[0] == 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[0] == 1, y'[0] == 0}, y, {x, 0, 2*Pi}]

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

enter image description here

$\endgroup$
  • $\begingroup$ Thanks. Now would it be possible to come up with an equation that would approximate that differential equation with a function? $\endgroup$ – Omkar Vaidya Jan 23 '18 at 10:21
  • $\begingroup$ I also expected the plot to oscillate, like a pendulum would $\endgroup$ – Omkar Vaidya Jan 23 '18 at 11:21
  • $\begingroup$ 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. $\endgroup$ – Omkar Vaidya Jan 23 '18 at 13:46
  • $\begingroup$ 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[0] == a, y'[0] == 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. $\endgroup$ – Omkar Vaidya Jan 23 '18 at 14:04
  • 1
    $\begingroup$ Try sol = NDSolve[{y''[x] == -(g/l) Sin[y[x]], y[0] == 1, y'[0] == 0}, y, {x, 0, 2*Pi}] $\endgroup$ – Sjoerd Smit Jan 23 '18 at 14:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.