Docsity

Practice Midterm Exam - Introduction to Engineering Computing | ENGR 0012, Exams of Engineering

Toggle sidebar
bg1
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
=
=
=− = −
=−
∑
∑
pf2

Partial preview of the text

Download Practice Midterm Exam - Introduction to Engineering Computing | ENGR 0012 and more Exams Engineering in PDF only on Docsity!

ENGR 0012/0711 - Fall 2005

Midterm Exam – Computer Part

Your Name: ________________________________________________________________________

Score _______/

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 i i i n i i

SSE

r SSE y f x

SST

SST y y

=

=

ENGR 0012/0711 - Fall 2005

Midterm Exam – Computer Part

Your Name: ________________________________________________________________________

Program Requirements :

  1. Your main script must contain your name, group number and class section as well as today’s date in comment lines at the top.
  2. Your main script must use comments throughout to detail what you’ve done.
  3. Begin by displaying the header by calling function 1.
  4. Use a loop to allow the user to analyze more than one data set. Control the loop by using the letters y or n. Check for user input errors, so the user must enter an (N or n) or (Y or y).
  5. Next, in the main script call function 2 to load the data. Return the x and y data and plot the data using green diamonds. Provide the user a chance to view the plot before continuing.
  6. Next call function 3 and display the mean and standard deviation for x, then the mean and standard deviation for y to the command window.
  7. Finally call function 4 so that the user can compute and determine the best fit for the data (linear or any order polynomial).
  8. The functions must perform the tasks as specified above.
  9. Make sure your program is clean and doesn’t display variables to the command window when they are not needed. Be sure to title and label any plots.
  10. When you are finished, save your main script and all the functions to a folder called “ your last name _midterm” (example “Bursic_midterm”). Drop your folder into your instructor’s preferred drop folder. ( Make sure to check that you have successfully dropped your files before turning in this paper with your name on it.)

Additional note if you are having trouble getting the functions to run: Comment out the function calls and create “dummy” variables that you are supposed to return from the functions. If you cannot get Function 4 to work, simply end your program after calling Function 3. You will get partial credit for the work you are able to complete.

Sample Program Output:

This program was written by Dan Budny Group R01, Budny 6 pm section Oct 26, 2005

This is a very fancy program to complete simple data analysis It will compute means and standard deviations as well as allow the user to fit a line or curve to a set of data Please enter the name of your data file: midterm_data1.dat Press any key to continue The mean of the x data is: 26.

The standard deviation of the x data is: 18.

The mean of the y data is: 5.

The standard deviation of the y data is: 5.