CS 151L – Fall 2014 Programming Assignment 5

Transcription

CS 151L – Fall 2014 Programming Assignment 5
CS 151L – Fall 2014
Programming Assignment 5
Due: Wednesday, October 15, 2014 at 11:59 PM
(For this assignment, you will need to email MATLAB scripts cs151f14assn5.m, assn5mag.m and
assn5phase.m to your TA. These scripts must be well-commented so the graders can follow your
work.)
A mass m is suspended from a spring on the ceiling whose spring constant or modulus is k. It is
also attached to a dashpot which provides viscous damping. A dashpot is a mechanical device or
a damper that resists motion through friction. Common applications include door closers (media
devices) to prevent “slamming” of the door. An example of damping can be found at
http://www.coolmath.com/dampfunction1.htm.
For this problem, you have a magnification factor (which is based on the damping ratio) that is
2rd
1
defined as m 
and a phase of tan  
. This program will use these
2
2
2 2
1

r
1  r   2rd 
equations to plot the magnification ratio versus the frequency ratio r and the phase angle ϕ versus
r.
Create the following two functions:
1. Create a function called assn5mag that has two arguments, the frequency ratio and the
damping value. The function will return one value, the magnification factor. Use the
equation defined above to perform the calculation. Keep in mind that the frequency ratio will
be a matrix of values while the damping value will be singular.
2. Create a second function called assn5phase that also has the same two arguments and returns
one value, the phase angle. You will need to solve the second equation for the angle and use
that in the calculation. Be sure that this function returns the value in degrees, not radians.
Once these functions are complete, create a cs151f14assn5.m file that will perform the following:
1. Assign the frequency ratio to values between 0 and 3 with an increment of 0.01.
2. Create a new figure window.
3. Run the function 5 times with the values of 0, 0.2, 0.3, 0.5 and 1 using the following steps:
a. Call the magnification factor function with the ratio matrix and a damping value.
b. Plot the magnification factor versus the frequency ratio where the frequency ratio is on
the horizontal axis.
4. Change the axis so that the horizontal axis runs from 0 to 3 and the vertical axis runs from 0
to 3.
1
The second part of the assignment needs to take into account the fact that the inverse tangent
returns values in the first and fourth quadrants. Values on the graph need to be in the first and
second quadrants, so there need to be some manipulations to make it graph properly.
5. Create a new matrix of values, r1, that have all the r values that are less than and equal to 1
(use the find function).
6. Create another matrix of r values, r2, that are greater than 1 (again using the find function).
7. Create a new figure window.
8. Run this function 5 times with the same damping values as in procedure 3 and follow these
steps:
a. Calculate the phase angle of the r1 values.
b. Calculate the phase angle of the r2 values.
c. Plot the first phase angle values versus the r1 values where the r1 values are on the
horizontal axis.
d. Plot the second phase angle values versus the r2 values. However, in this plot, you will
need to add 180 degrees to the second phase angles to move them in to the second
quadrant from the fourth quadrant.
9. Change the figure axis so that the horizontal axis runs from 0 to 3 and the vertical axis runs
from 0 to 180.
Your plot should look similar to the following plots:
2