PHYSICS 241 -- Assignment 2 Due Thursday 9/11 by midnight by

advertisement
PHYSICS 241 -- Assignment 2
Due Thursday 9/11 by midnight by upload. Discussion is on paper in class
or by text file uploaded.
Readings: Pratap Chapter 4.
Handout from Excel for Scientists and Engineers
PROBLEMS
RS-2.1a Write a program (script or function or some combination) to create and save a two column text file as follows:
%Data file for testing derivative function
%360 evenly spaced points between 0 and 2pi seconds, function is sin(t)
%360 evenly spaced points between 2pi and 4pi seconds, function is t-0.16*t^2
%360 evenly spaced ponts between 4pi and 6pi seconds, function is sin(2t)
%Time (seconds) %Position (meters)
RS-2.1b Write another program to create and save a data file as two columns of text as follows:
%Data file for testing derivative function
%9 evenly spaced points between 0 and 2pi seconds, function is sin(t)
%9 evenly spaced points between 2pi and 4pi seconds, function is t-0.16*t^2
%9 evenly spaced ponts between 4pi and 6pi seconds, function is sin(2t)
%Time (seconds) %Position (meters)
RS-2.1c Write a program to create some other function of time you make
up that is defined for times between -10 and 10 seconds and to write your function output to a file.
RS-2.2 Write a program that plots your position function (from Probs 2.1) as well as its derivatives, calculated analytically.
(e.g., If your function from 2.1c was
y=t^2, you would plot y=t^2, y=2*t and y=2 on the separate plots (use the subplot command) with the same time axis. (I
hope you pick a more interesting function than y=t^2!)
Each data point should be plotted with an x AND there should be a line through the points as well.
RS-2.3 Write a program that also plots position. velocity and acceleration, but first reads the position data from a file, then
does the derivatives numerically (instead of analytically as for 2.2). The script should consist of at least two parts:
1) A "main script" that reads a data file of position and time, passes the data to a time derivative function and uses the result
to plot position, velocity and acceleration. Plot position, velocity and acceleration vs. time in three graphs with the same
time axis. Make sure to label axes. Operate your script on the raw data from RS-2.1a, RS-2.1b and 2.1c.
2) A separate time_derivative function to take a derivative of position and time data (or velocity and time data). Your
derivative function should handle a data vector of any length, and it should return a derivative with the SAME length (# of
points) as the position or velocity vector passed in.
The derivative function should be defined as follows:
deriv = function derivative(X,t1,t2)
% DEFINITIONS: X is an array of position, velocity or other data to be differentiated.
% t1 and t2 are single numbers representing the first time and the last time of the data contained in X.
%ASSUMPTIONS AND HINTS: You may assume that the time between data points in X is
%evenly spaced. The matlab function "length" applied to X can help you figure out
%how to calculate delta-t between individual data points.
RS-2.4 Write another function that integrates any data set passed in. In should be in this form.
integ = function integral(X,t1,t2)
% DEFINITIONS: X is an array of acceleration, velocity or other data to be integrated.
% t1 and t2 are single numbers representing the first time and the last time of the data contained in X.
% CLARIFICATION: The way the function is defined, it looks like a definite integral. It IS a definite integral, but
%it's not one number. It's the defnite integral from the 1st point to the 2nd, then from the 1st to the 3rd and so on up to the
1st %through the Nth.
RS-2.5 Read in the data sets from problem 2.1. Using subplot, plot the data, it's derivative, and the integral of the derivative
for both the 360 and the 9 point functions. (Show each data point as an X and have a line thru) Discuss the results.
Download