# C++ Harmonic Oscillator (with Force)

1. May 18, 2015

### ChrisVer

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

With different $F$ 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. May 18, 2015

### ShayanJ

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.