Homework Help: Simple Energy Question based on SHM

1. Feb 20, 2016

RJLiberator

1. The problem statement, all variables and given/known data
I am taksed with putting some simple harmonic motion (in this case linear harmonic motion) into graphs.
For my first graph, I am graphing theta vs. time and analyzing three different numerical methods for the solution (Euler, Euler-cramer, Runge Katta).
For my second graph, I am looking at the Energy vs. time based on these results.
Attached in the solutions are my results.

2. Relevant equations

3. The attempt at a solution

MOTION:

ENERGY:

Unfortuantely the labels are hard to read from jpg format. But the Euler method= black, the euler-cromer = red = runge-kutta method = blue.

My question is this: I know that my linear harmonic oscillator graph for motion is correct. I have a feeling my energy calculation is wrong, which is why I am posting here.
My energy calculation for euler method seems consistent. The energy continues to grow, infinite energy! Which is the problem with the Euler method here.

But my energy calculation for Runge-kutta and Euler-cromer method, I would have thought, were supposed to be a constant.
Or is my interpretation wrong and my graph actually correct?

2. Feb 20, 2016

RJLiberator

I am going to post my second problem as it is highly related:
For this code, I am graphing Ideal Motion (red), Motion with dampening (black) , and then motion with dampening and a driving force (blue).

The energy calculations should be the same from my initial post, which is why it is relevant.

As we see, the black energy curve flatlines, which seems consistent with the graph of its motion. However, should it be flatlining at the 1800 mark like it does, or at the 0 mark? That's confusing to me.

Similiarly, red and blue don't seem to be losing or gaining much energy in the graph of motion, but they shoot up linearly quite fast.

3. Feb 20, 2016

RJLiberator

I think I might have solved it while I was creating the post above!
I deleted a part of my code for my energy calculation, and I get this:
So the red curve we see a consistent energy which works with it's graph of motion.
The blue energy curve also works with the motion seen as at first it starts high then goes consistent.
The black curve now 0's out.

Looking good?