# Homework Help: Calculating the energy of a harmonic oscillator

1. Aug 2, 2011

### demonelite123

the general solution is given by x(t) = Acos(ωt) + Bsin(ωt). Express the total energy in terms of A and B and notice how it is independent of time.

my book derives a formula earlier which says $$\frac{\partial{S_{cl}}}{\partial{t_f}} = -E$$ where $$S_{cl}$$ is the classical path defined by $$S_{cl} = \int L dt$$ where L is the lagrangian.

i know that the lagrangian for a harmonic oscillator is L = $$\frac{1}{2}m\dot{x}^2-\frac{1}{2}kx^2$$

so i tried $$\frac{\partial{S}}{\partial{t}}$$ = $$\int (\frac{\partial{L}}{\partial{x}} \dot{x} dt + \frac{\partial{L}}{\partial{\dot{x}}}\frac{d\dot{x}}{dt} dt)$$

and i have $$\dot{x} = -A\omega\sin(\omega t)+B\omega\cos(\omega t)$$ as well as $$\ddot{x} = -A\omega^2\cos(\omega t)-B\omega^2\sin(\omega t)$$

so after substituting and taking the antiderivative, i get something very messy:
$$\frac{1}{2}(ma^2\omega^2 + kB^2\omega^3)(t - \frac{1}{2\omega}\sin{2\omega t})+\frac{1}{2}(mB^2\omega^2 + kA^2\omega^3)(t+\frac{1}{2\omega}\sin{2\omega t}) - \frac{1}{2\omega}(kAB\omega^3 - mAB\omega^2)\cos{2\omega t}$$

i am supposed to get something only in terms of A and B but it seems like it will since nothing really cancels out. did i make a mistake? help on this will be greatly appreciated.

2. Aug 2, 2011

### vela

Staff Emeritus
I don't think the units on some of your terms work out, so you apparently made a math error somewhere. Recheck your calculations.

3. Aug 2, 2011

### JFuld

for harmonic oscillator V(x)=1/2kx^2

try maximizing E= V(x)+kinetic energy

KE = 1/2(m)(dx/dt)^2

its a classical solution but i think it still applies