Question: For this assignment you are given two sets of data. First a test set: x y 1 4 2 5 3 8 And a second

For this assignment you are given two sets of data. First a test set:

x

y

1

4

2

5

3

8

And a second set of experimental data for a parachutist which gives the velocity of the parachutist versus the time since the chute opened:

Time (s)

Velocity (m/s)

1

50.00

2

49.00

3

46.00

4

45.50

5

46.00

6

45.00

7

42.90

8

41.50

9

39.00

10

35.60

11

31.00

12

27.50

13

23.00

14

16.30

15

10.00

In this assignment you will write five M-files (four functions and one script):

Function getData: In this function you will start by hardcoding the test data above into two 1D arrays. The input parameters to the function will be void (that is, no input) and the output will be the two arrays defined in the function. Once you have your program working, you can then substitute the experimental data above. As for course Assignment 1 you will want to pre-allocate space for your arrays. Consider the fact that you are writing a program that will be used for a variety of experimental data. Therefore, you want the size of you pre-allocated arrays to be as large as the largest set of data you expect to have. This will reduce any future modifications your program may need.

Function regressConst: In this function you will calculate a0 and a1 as defined above. The input to the function will be the two arrays define in getData and the output will be a0 and a1. You must use for-loops to calculate the summations and may not use MATLAB built-in functions. Hint: it may be advisable to calculate each of the four distinct individual summations separately into variables and then use these variables to calculate a0 and a1.

Function findLine: This function will use a0 and a1 to array values of the find straight line which is the best fit to the data points. The input to the function will be a0 and a1 and the output will be two vectors that give the data of the straight line (x, y). You may want to use an increment of 0.1 and you can hardcode the minimum and maximum values of the domain of the function. Select what you think are appropriate values for the domain.

Function outputRegressData: This function will plot the results. The input to the function will be the data from the straight line obtained from the function findLine and from the experimental data obtain from getData. The function will have no output data. The plot of both sets of data should be on the same graph. The data from findLine should be a continuous line and the experimental data should be displayed with only discrete symbols. For example, given two vectors of data, x and y, to plot the function as discrete points using the symbol +, you can use the MATLAB command:

plot(x, y, +);

The Driver: In addition to the function you must write a MATLAB script to control the function. It will work as follows:

First, call the function getData to obtain the experimental data

Second, call the function regressConst passing the data obtained from getData to obtain a0 and a1.

Third, call the function findLine passing a0 and a1 to obtain the data of the straight line.

Fourth, call the function outputRegressData passing the data of the original data points and the data of the straight line to plot both sets of data.

You are required to upload the following files to CLEW:

getData function

regressConst function

findLine function

outputRegressData function

The driver script

A documentation file explaining what your program does and how to run it. Paste a graphic image copy of your plot in this file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!