Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ Harmonic Oscillator (with Force)

  1. May 18, 2015 #1


    User Avatar
    Gold Member

    I was wondering whether it's possible to write a code in C++ that would be able to solve the Harmonic Oscillator:
    [itex] \ddot{x} + \gamma x = F_{external}(t,x)[/itex]

    With different [itex]F[/itex] function inputs... I thought about creating a function with if clauses, so for different inputs by the user, the force F would be described by a different function...What do you think?
  2. jcsd
  3. May 18, 2015 #2


    User Avatar
    Gold Member

    The whole program surely needs more thought but for the force function, its better to use function pointers. Then you can work with an unspecified function which is later specified by the input from user. But I should think more about that because the program where I used this method was doing a simpler job so there may arise some complications.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook