# Classical mechanics & runge-kutta

1. Jan 29, 2006

### gulsen

We have a pendullum in a car, that is being pulled with:
a) constant F force
b) connectec to a spring, with force F = -kx

The physics part is done, and we have 2 differential equations (non-lineer), and we're supposed to write a C program to calculate theta(t) and x(t) from them. We should solve them with Rugne-Kutta. Here they are:

$$(M+m)x'' + mL\theta''cos(\theta) - mL(\theta')^2 sin(\theta) - F = 0$$
$$mL^2\theta'' + mLx''cos(\theta) + mgLsin(\theta) = 0$$

The problem is, we've learned how to solve
$$f'' + p(t)f' + q(t)f + r(t) = 0$$

but these equations have two independent variables. Now, what's the path to follow?

(note: yes, these two equations are confirmed to be enough to get values for x(t) and theta(t))

2. Jan 30, 2006

### pervect

Staff Emeritus
Numerical recipies in C is online now:

http://www.library.cornell.edu/nr/bookcpdf.html [Broken]

The general approach is to convert your system of second order differential equations into a system of linear first order differential equations.

See for example

http://www.library.cornell.edu/nr/bookcpdf/c16-0.pdf [Broken]

and later chapters.

Last edited by a moderator: May 2, 2017
3. Jan 30, 2006

### franznietzsche

I actually solved the simple pendulum this way in high school. What you need to do is use an RK4 to get $$\theta '$$ and $$x'$$ from the second order equations, and then use the same RK4 to do a simple time integral of that velocity ($$dx = vdt$$). At least, thats how I would do it.