{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

uniqueFit

# uniqueFit - subplot(round(length(x/2,2,1%plots the original...

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

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 newx = linspace(min(x),max(x)); %gets the new x values
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: subplot(round(length(x)./2),2,1); %plots the original data in the first position plot(x,y,'b*'); title('Original Data'); for ind = 1:order subplot(round(length(x)./2),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 %determines the ending of the order fit for the title of the graph end end...
View Full Document

{[ snackBarMessage ]}