Please turn in this assignment (and all future assignments for this course) by emailing them to me . Please use the subject of "Honors 270 HW6" (note that the spacing matters) for this assignment (if you use the link above, the subject will be added automatically). Please attach separately the source code to all the programs that you write for this assignment. Each program should be attached as separate file to make it easier for me to read them. When answering the questions themselves feel free to answer directly in the body of your message or attach your answers as a separate file. You may want to copy and paste the questions into your message.
mx'' +cx' + kx =0where m is the mass of the oscillator, x'' is the acceleration, c is the damping constant, x' is the velocity, k is the spring constant, and x is the position of the oscillator.
We first isolate the acceleration
x'' = -1/m (cx' + kx)
This differential equation can be solved numerically using difference equations:
Δx' = -1/m (cx' +kx) Δt x'i = x'i-1 -1/m (cx'i-1 +kxi-1) Δt
xi = xi-1 + x'iΔt
In those equation the subscripts are indices for arrays.
Your program will first read in input values from a one of 3 files: damp1.txt, damp2.txt, and damp3.txt. Those files hold the mass (m), damping constant (c), spring constant (k), time step (dt), initial amplitude (A), and number of points to save (n), in that order.
Once your program has read in those values, it should setup up empty arrays for position (x) and velocity (x'=v), and a filled time array. The initial position is equal to the amplitude (x = A) and the initial velocity is 0 (v =0). It should then use a while loop to calculate the velocity and position at each time. Then is should plot create separate velocity and position plot of the result. It should also save the time, position, and velocity to a text file. Each row of the text file should be a time, followed by the position and velocity at that time.
You should run your program for each of the input files, and you should turn in copies of your plots and output text files for each of the run.
Also, for each of your runs, find the time at which the position goes from positive to negative.