uniqueFit - newx = linspace(x(1),x(end)); %gets the new x...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function uniqueFit(x,y) %This function takes in x and y data and then creates a plot of all %the fits up the the last unique fit. Each unique fit will be its own %subplot, with two subplots per row. % Specifics: %- Plot the original data using blue stars. Title your plot 'Original % Data'. %- Plot all the rest of the data with the original points in blue stars % and whatever order fit in a red line. %- Use 100 linerally spaced points between the first and last x point % for new x values. %- The title of the fitted plots should read '__ Order Fit', where the % blank is the ordinal number of the fit. Example, a first order fit % should read '1st Order Fit', while second order fit will read '2nd % Order Fit' and so on. order = length(x) - 1; %determines the order of the polynomial
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: newx = linspace(x(1),x(end)); %gets the new x values subplot(length(x),2,1); %plots the original data in the first position plot(x,y,'b*'); title('Original Data'); for ind = 1:order subplot(length(x),2,ind+1) %creates subplots for each different order of the polynomial coeff = polyfit(x,y,ind); %gets the coefficients of the polynomial best fit line for that order newy = polyval(coeff,newx); %gets the new y values based on the coefficients and the new x values plot(x,y,'b*',newx,newy,'r'); %plots the original data and the best fit line switch ind case 1 title(sprintf('%dst Order Fit',ind)); case 2 title(sprintf('%dnd Order Fit',ind)); case 3 title(sprintf('%drd Order Fit',ind)); otherwise title(sprintf('%dth Order Fit',ind)); end end end...
View Full Document

This note was uploaded on 10/21/2010 for the course CS 1371 taught by Professor Stallworth during the Spring '08 term at Georgia Institute of Technology.

Ask a homework question - tutors are online