
ENGR 0012/0711 - Fall 2005
Midterm Exam – Computer Part
Your Name:________________________________________________________________________
Score _______/100
Section: Bursic (2 PM) Budny (6:30 PM) Vasko (6:30 PM)
Your assignment is to write a MATLAB script to do data analysis as follows:
Your main script must call at least four (4) functions and perform the tasks as described below.
1. Function 1: Display a header
a. This function simply displays text, and thus requires no inputs or outputs. It should display your
name, group number and class section as well as today’s date and something like “This program
loads and analyzes data…etc. etc.”
b. Suggested first line of this function file: function header
2. Function 2: Load Data
a. This function must load x and y data that is in either columns or rows (you will run your
program with either “midterm_data1.dat” or “midterm_data2.dat” – get these from the Get
Folder.)
b. The function should ask the user for the name of the file.
c. Suggested first line of this function file: function [ x,y] = load_data
3. Function 3: Computes the mean and standard deviation of a set of data.
a. This function should return the mean and standard deviation of a set of data to the main
program.
b. You may use built-in MATLAB functions if desired.
c. Suggested first line of function file:
function [ you determine what variables here, if any] = analysis(you determine what
variables here, if any)
4. Function 4: Allows the user to either try a linear fit or any order polynomial.
a. Ask the user which fit they’d like to try and use a menu with a switch case to perform the
necessary operations.
b. Plot the data and the fit line/curve then allow the user to decide if the want to try a different fit
for the data set. For the linear fit, display the equation of the line on the plot. For the
polynomial check the order of the degree entered by the user.
c. Add labels to the plot. The provided data is from a study of x = frying time (in seconds) for
tortilla chips versus y=moisture content (%) in the chips.
d. Suggested first line of function file:
function [you determine what variables here, if any]=fitting(you determine what variables
here, if any)
5. Bonus Function 5: Computes the r-squared value for a linear fit.
a. This function should be called from within Function 4 and should compute the r-squared value.
()
()
2
2
1
2
1
1 , where, ( )
n
ii
i
n
i
i
SSE
r SSE y f x
SST
SST y y
=
=
=− = −
=−
∑
∑