1
$\begingroup$

I need to make a C# simulator for a simple pendulum. I have been searching the web for 3 days and I am stuck.

The problem is I have found many equations that would give the angle position as a function of time, which is perfect for my needs for making a visual simulation but the problem is those functions only works for angles smaller than 10, but I should be able to simulate from any angle. Example of a equation that only works for small angles:

enter image description here

Source: http://hyperphysics.phy-astr.gsu.edu/hbase/pend.html#c4

And the equations that should work for any angle (Amplitude) are too complicated as it involves differential equations, and derivatives. I don't know how to implement these in C#. Example of a equation that I think would work but I don't know how to use:

enter image description here

Source: http://www.sbfisica.org.br/rbef/pdf/070707.pdf

the problem of this last equation is the "sn" that is Jacobi elliptic function sn(u;m) u, and I don't know how to use in C#

Can someone help? maybe with another equation that I could use programmatically, or helping me understand how I could use this last one if it would really works.

$\endgroup$
  • 8
    $\begingroup$ The point of simulation isn't to simply apply a closed form solution (what you are trying to do), but to allow you to do without this elusive beast and work from the easily found equation of motion. Convert the EoM (a differential equation) to an appropriately chosen difference equation approximation and go to town. $\endgroup$ – dmckee Apr 24 '15 at 2:11
  • 1
    $\begingroup$ khanacademy.org/computer-programming/forphys/6505289796943872 the "degrees" function turns radians into degrees, (multiplication by 180/Pi) which the trig functions need. no further explanation needed $\endgroup$ – user12029 Apr 24 '15 at 2:18
  • 3
    $\begingroup$ @NeuroFuzzy I'd probably also suggest that the OP look up something like the Runge-Kutta, backward Euler, as that one simply uses Euler. Clearly from the simulation on the Khan academy page it seems to give reasonable results, but in general it can lead to problems. Carlos, I suggest you should read en.wikipedia.org/wiki/Euler_method , especially en.wikipedia.org/wiki/Euler_method#Modifications_and_extensions as well as NeuroFuzzy's link. $\endgroup$ – WetSavannaAnimal Apr 24 '15 at 3:36
  • $\begingroup$ Without friction you additionally know that it is periodic, so half period simulation is sufficient, avoiding error accumulation for large times. $\endgroup$ – mikuszefski Apr 24 '15 at 12:04
  • $\begingroup$ Just be careful with Runge-Kutta as it breaks ergodicity. For mechanical problems a symplectic scheme like Leap-Frog is favorable. $\endgroup$ – Martin Ueding Jul 10 '16 at 11:08
1
$\begingroup$

If you really do not want to simulate (despite your tag), you need to program the elliptic function and the Jacobian amplitude. This is done in the Numerical Recipes. You probably need to adapt something to C#.

If, on the other hand, This is about simulation, I suggest you go for the solutions provided in the comments to your question, i.e. some Runge-Kutta integration or similar, which by the way is also provided by the link above.

$\endgroup$
  • $\begingroup$ Runge-Kutta might be a way to start. You will see that at some point the energy is not conserved (as it should it). Simulating mechanics with Runge-Kutta is not very good as it breaks time reversal symmetry. If you want, still try it with Runge-Kutta and watch some conserved quantity like the total energy. Then use a symplectic integration routine like leap frog. That will conserve the energy and give better results although it is of lower order than classical Runge-Kutta. $\endgroup$ – Martin Ueding Jul 10 '16 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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