Question: Write and run a C++ program that simulates a simple harmonic oscillator using the Euler-Cromer algorithm. Have the code graph its position versus time, and

 Write and run a C++ program that simulates a simple harmonicoscillator using the Euler-Cromer algorithm. Have the code graph its position versus

Write and run a C++ program that simulates a simple harmonic oscillator using the Euler-Cromer algorithm. Have the code graph its position versus time, and plots the potential, kinetic, total energy, and percent error between the calculated and theoretical total energy of the oscillator. Make sure it plots for 5-10 periods of oscillation to see if there is any increase in the error. Using command-line arguments, the user should be able to input the natural frequency squared (2), the initial position, xo, and the initial velocity vo (in that order). Use the following form for Hooke's Law 2 Hooke _ _mwX where we will use x 0 as the equilibrium point. a) What is the percent error in the total energy for a time step of 0.01 s? (b) What is the percent error in the total energy for a time step of 0.001 s? (c) [sho anh.cpp| (extra credit) Now modify this code (and rename it) by adding an anhar- monic term, where 2 Run this for several values of and write a little analysis of what the particle behaves like with this additional term. Do you think your code is simulating the system accurately? You should explain in detail what makes you think you can "trust" the code. Write and run a C++ program that simulates a simple harmonic oscillator using the Euler-Cromer algorithm. Have the code graph its position versus time, and plots the potential, kinetic, total energy, and percent error between the calculated and theoretical total energy of the oscillator. Make sure it plots for 5-10 periods of oscillation to see if there is any increase in the error. Using command-line arguments, the user should be able to input the natural frequency squared (2), the initial position, xo, and the initial velocity vo (in that order). Use the following form for Hooke's Law 2 Hooke _ _mwX where we will use x 0 as the equilibrium point. a) What is the percent error in the total energy for a time step of 0.01 s? (b) What is the percent error in the total energy for a time step of 0.001 s? (c) [sho anh.cpp| (extra credit) Now modify this code (and rename it) by adding an anhar- monic term, where 2 Run this for several values of and write a little analysis of what the particle behaves like with this additional term. Do you think your code is simulating the system accurately? You should explain in detail what makes you think you can "trust" the code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!