Lab 05 - Jay1337/computational_physics GitHub Wiki
Goal
In this lab our overall goal was to be able to visualize and analyze experimental data for a mass oscillating on a spring. In doing this we needed to determine the analytic solution describing the motion, where we ended up implementing the Euler and Euler-Cromer method in order to do so. The Euler and Euler-Cromer numerical methods our what allowed us to model our oscillation motion, and after visualizing both numerical solutions against the analytic solution we could see between the Euler and Euler-Cromer method which is better in modeling harmonic motion, as well seeing how energy is conserved with the Euler-Cromer method.
Overview
This lab can be seen and described through three parts, where in part 1 we are visualizing data and determining and plotting the analytical solution for a simple harmonic oscillator. In part 2 we are aiming to model our motion with the Euler method, and in part 3 we are modeling our motion with the Euler-Cromer method.
Part 1
In part 1 we started with importing real-world experimental data for a mass-spring system so that we could get a sense and see the data and values associated with simple harmonic motion. Said data was seen through our position vs. time plot which led us to be able to visualize the oscillatory pattern. Through analyzing the graph, we were able to gain values for the amplitude, angular frequency, and phase shift, which are the defining parameters of the SHM equation which is seen by x(t) = A cos(ωt - ϕ). A represents the peak displacement from equilibrium, ω is found through using the equation ω = 2π/T, and ϕ accounts for the initial phase offset of the oscillation. These parameters are used to construct an analytic model of the oscillator which we also plotted against the experimental data in order to validate the accuracy of the solution.
Part 2
In this second part we used the Euler method in order to model the mass on a spring, and if we can see the conservation of energy through the Euler method. In order to calculate the Euler method we used Newton's second law and Hooke’s law (F = -kx) in order to calculate acceleration, velocity, and position step-by-step over time by using arrays for each in order to approximate each next interval.
We used our analytical solution form part in order to determine the accuracy of the Euler method, and it was easy to see through our graph that the Euler method was not accurate and not a good approach in modeling oscillatory motion.
Through this lab we could also see that the Euler method does not conserve energy as when we calculated the system's mechanical energy (sum of kinetic and potential energy) over time to investigate whether the Euler method conserves energy it was evident the Euler method does not conserve energy. Through the Euler method we see a gradual increase or decrease in energy showing how there is no conservation of energy.
Implement the Euler numerical method.
Part 3
In part 3 we used the Euler-Cromer method instead of Euler method in order to see if it would conserve energy and be better in modeling simple harmonic motion. Unlike the Euler method, where position is updated using the old velocity, the Euler-Cromer method updates velocity first and then uses the new velocity to update position. This change vastly adjusts things and when plotting the Euler-Cromer method against the analytical solution we found that the Euler-Cromer method is indeed reliable for modeling simple harmonic motion as well as conserves energy. The energy vs. time plot tracks the total mechanical energy (kinetic + potential) of the system throughout the simulation and a constant energy value suggests a stable method which is what we saw with our Euler-Cromer method.