Starting from:

$35

HW6B Solution

HW6B Solution

6.4
Non-Polynomial Models (“Transforming” the Data)
xi
yi

The four data points at right are measurements of the amount of mustard (yi) le:







behind in a container as a func<on of the force (xi) you squeezed the bo?le. You
2
6

want to calibrate an analy<c model y = f(x) for future mustard-container analysis.
3
5

You’re considering the following five models for f(x):




4
3

i. 
f ( x) = a + bex
for two unknown coefficients a and b.






5
1







ii. 
f (x) = 12 P xQeSx
for three unknown coefficients P, Q and S.




iii. 
f (x) = ux2 + wx +1
for two unknown coefficients u and w.
iv. 
f (x) =

a

for two unknown coefficients a and k.


1+ kx





v. 
f (x) = X 0 +V0 x +
1
(9.8) x2 for two unknown coefficients X0 and V0.


2


For EACH model (i) through (v), complete both tasks below:

(A) Write the problem out in matrix form r = y – A c. Be sure to explicitly …

•  show me how you’re analy<cally “transforming” the model (if necessary),
•  define the vector c in terms of the unknown(s) in the model,
•  write out the values of all the elements in the vector y and matrix A using the provided data.

(B) Use MATLAB to evaluate the least-squares best-fit c using the command c = A \ y …
•  evaluate the vector c, and all the unknown coefficients in the model (write each value to at least 4 significant figures),

•  subs<tute the coefficients back into the general form to write out the final equaMon for the best-fit model f(x).



6.5 Non-Polynomial Models (using polyfit)

For EACH of the five models above, show me how (IF POSSIBLE) you can get the unknown coefficients directly from using the command P = polyfit(X,Y,n) (thereby skipping all the steps of crea<ng the matrix form). That is,

•  Write out explicitly what you use for vectors X and Y, and your choice for the value of n.

•  Also show explicitly how you use the output P to give you the required unknown(s).

If you don’t think you can use polyfit for that par<cular model, then say so explicitly.



Everything above is to be wri?en out on paper. You’re using MATLAB to solve for c = A \ y, but just write values out. Don’t submit your answers on Carmen.
HW6B

6.6 Trying to correlate a random data set!

Load the y and t data provided in the file HW6data.mat into MATLAB (type: load HW6data) . Make a quick plot of y versus t (i.e. plot(t,y,’o’) ) to see what it looks like, then write a code called HW6_6.m with commands that do ALL of the steps (a) through (f) below. That is, I should be able to run your code and it would automa<cally create all the best-fit models, evaluate the requested values, and make all the plots.

a)  Determine the 1st-order polynomial, f1(t) = a1 t + a0 , best-fit of the data.

b)  Calculate the R2 value of the least-squares best fit model f1(t). (Hint: you might find the built-in command mean(Y) helpful).

c)  Determine the 2nd-order polynomial, f2(t) = a2 t2 + a1 t + a0 , best-fit of the data.

d)  Calculate the R2 value of the 2nd-order least-squares best fit f2(t).

e)  Plot the original (t,y) data as circles, i.e. plot(t,y,’o’), overlaid with lines of the 1st-order best-fit model f1(t) and the 2nd-order model f2(t) on the same plot. Make the line for f1(t) in blue and the line for f2(t) in red. Save this plot as PLOT6A.pdf.

f)  Plot the residual errors, i.e. plot(t,r,’o’), for the residual error vector of the 2nd-order model, r = y – f2(t). Save this plot as PLOT6B.pdf.


Do not hand in anything on paper for 6.6. Everything below must be submi?ed on Carmen:

•  Upload your documented code HW6_6.m, and both plots PLOT6A.pdf and PLOT6B.pdf.

•  Write “1st-order fit”, followed by the coefficients a1, a0 and the R2 value of the best-fit model f1(t) in the comment box.

•  Write “2nd-order fit”, followed by the coefficients a2, a1, a0 and the R2 value of the best-fit model f2(t) in the comment box.

•  Use the results from (b) and (d) – (f) to comment explicitly on the “goodness” of the final fit f2(t) in the comment box. What exactly does the shape & distribu<on of residuals, and both of the R2 values tell you? (Be succinct, specific and mathema<cal in your write-up using ideas from class, not a vague essay. Think about how this problem brings together the “engineering step” ideas from class.)

More products