A8

ENGR 17
Assignment 8
Due: Next Tuesday
Create an A8 folder to hold all your work
1) Function Discovery
Create a new script called prob1.m For this problem you will create 3 separate plots for part a, b, and c. When they are
all done you will arrange them on one pane using the subplot command, as the following instructions show.
Begin with comments indicating the name of the script and your name.
% part A:
% create x and y vectors
% plot x and y using plot, semilogy, and loglog. Find the one that looks the straightest.
% use the curve appropriate to the straightest plot (linear, exponential or power) to derive model coefficients m and b.
% create a smooth model: make xmodel with 10 times the sample density of x and generate ymodel from xmodel
% plot model and data on linear axes: plot(x,y,'s',xmodel,ymodel) and add xlabel, ylabel and title
When partA works, deactivate it (comment out) and add lines that repeat the steps on part B and C. reuse x, y, xmodel
and ymodel for each part.
When each part works, comment it out.
Finally, when parts A, B, and C all work, combine your three plots onto one pane. Activate all three parts. Put
subplot(1,3,1) at the start of part A, subplot(1,3,2) at the start of part B, and subplot 1,3,3 at the start of part C. Re-run
your script. You should get all three plots on the same pane. Save the plot as prob1.jpg
2) Regression Analysis
Make a new script in your A8 folder called prob2.m. Create a vector A (which will be the x-axis) and T (y-axis). For part
(a) you will simply use polyfit to create first, second, third and fourth order fits to the data. Plot these on a pane of 4
subplots, showing data and model. Also, for each model, compute J, S and r2 and add the value of r2 to the appropriate
subplot using the text command.
For part (b) to find the A that minimizes T (Amin), take the model polynomial, say p, containing the coefficients. The
minimum A will be at a point where the derivative of polynomial p is zero. We can find this in matlab using
roots(polyder(p)). Make sure the value you get for Amin matches the apparent min on the plot (there may be several
roots so make sure you pick the right one). Using text, add your answer for Amin to the subplot that shows the model
you used to calculate Amin.
Save your plot as prob2.jpg
3) Make a new script called prob3.m. Use plot3 to create this 3D plot and save as plot3.jpg.
4) Use a meshgrid from -12 to 12 for this one
5) Extra Credit (1 point)
This is not so hard if you set up your A vector with all ones in column 1, all x1 values in column2 and all x2 values in
column 3. Then use the matrix method for least squares shown in the beginning of lecture powepoints and demo to
derive the coefficients a0, a1 and a2.