## Honors **270** Assignment 6

### Due October 20

### Directions

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.

#### Damped Oscillations

In this assignment you will
write a program to calculate solutions to the damped oscillator problem which
has the differential equation:
mx'' +cx' + kx =0

where 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} +kx_{i-1}) Δt

x_{i} = x_{i-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[0] = A) and the initial velocity
is 0 (v[0] =0).
It should then use a
while loop to calculate the velocity and position at each time. Then it should
create separate velocity and position plots 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 first time at which the position goes
from positive to negative.