Lab 2: Model Fitting and Regression
In this lab, you'll apply what you've learned in sections 3.2-3.4 and 6.3.
Contents
Some useful MATLAB commands
Use help or doc for more information
- SUM: if v is a vector of length n, then sum(v)=

- POLYFIT & POLYVAL: p=polyfit(x,y,n) finds the least squares fit of the data to a model of the form
, where p is a polynomial of degree n. The variable p is just a vector containing the coefficients. Use command yy=polyval(p,xx) will evaluate the polynomial p at the point values stored in xx. - SEMILOGYX, SEMILOGY, LOGLOG: plots with logarithmic scales on one or both axes.
Assigned Problems
- Section 3.3 #8. Also plot the deviation for each model, and calculate the regression
. Use this information to decide which model you think fits the data best. Note: polyfit will not work for part c. - Section 3.3 #10. Hint: think carefully about which variable goes on the x-axis and which goes on the y-axis. Plot the deviations as well (use a logarithmic scale on the x-axis to help space out the points). Referring to figure 6.15 on p 227, which type of pattern do you see in the residual. What can you conclude? Finally, compute the same fit using a transformed least squares fit, as in section 3.3. Recall that this example is studied in section 2.2. Comment as to which method you think has done a better job, using whatever information (graphs, tables, etc.) is necessary to make your case.
- Section 3.4 #7. Do all parts, answer all questions.
- Section 2.3 Project 7. Use least squares to find the constant of proportionality for the model in this project and also for the data in table 2.6 on page 84. Then answer the question: Which of these two models do you think more accurately predicts the weight of the dreaded terror bird?
- Section 6.7 #2.