cubicpoly -...

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

View Full Document Right Arrow Icon
function cubicpoly(x,y) %Problem 14.3 n=numel(x); Z=[ones(n,1) x x.^2 x.^3]; a=Z\y; xx=linspace(min(x),max(x),50); yy=a(1)+a(2).*xx+a(3).*xx.^2+a(4).*xx.^3; plot(x,y,'o',xx,yy); title('cubic polynomial fit'); xlabel('x'); ylabel('y'); %Prints cubic function fprintf('\ny= %6.4f + %7.6fx + %6.5fx^2 + %7.6fx^3\n\n',a(1),a(2),a(3),a(4));
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Sr=sum((y-a(1)-a(2).*x-a(3).*x.^2-a(4).*x.^3).^2); %or in book ---> Sr=sum((y-Z*a).^2); St=sum((sum(y)/n-y).^2); %Calculates th coefficient of determination r2=1-(Sr/St); fprintf('\nr^2=%4.3f\n\n',r2);...
View Full Document

This note was uploaded on 09/27/2011 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

Ask a homework question - tutors are online