Study Guides (248,228)
United States (123,295)
ENGR 0011 (1)
Bursic (1)

# ErrorAnalysis.asv

6 Pages
137 Views

School
Department
Engineering
Course
ENGR 0011
Professor
Bursic
Semester
Fall

Description
function ErrorAnalysis(x,y,a,b) %This function is to caculate the errors %calculate the errors of different type plot if a==1 %use polyfit and polyval command to find the best fit coeff=polyfit(x,y,1); yline=polyval(coeff,x); %calculate the abs error absolute_error=abs(y-yline); %filter the date to find the rel error p=1; for i=1:length(x) if y(i)~=0 relative_error(p)=abs((y(i)-yline(i))/y(i)); p=p+1; end end %calculate the r^2 SSE=sum(absolute_error.^2); SST=sum((y-sum(y)/length(y)).^2); r2=1-SSE/SST; gtext(['r^2=',num2str(r2)]) disp(['R^2=',num2str(r2)]) minabs=absolute_error(1); maxabs=absolute_error(1); minrel=relative_error(1); maxrel=relative_error(1); minloc=1; maxloc=1; relminloc=1; relmaxloc=1; %find the max and min abs error and max and min rel error and location for i= 1:length(x) if absolute_error(i)maxabs maxabs=absolute_error(i); maxloc=i; end end for i=1:length(relative_error) if relative_error(i)maxrel maxrel=relative_error(i); relmaxloc=i; end end disp(['The min absolute error is ',num2str(minabs),' and the location is ',n um2str(minloc)]) disp(['The max absolute error is ',num2str(maxabs),' and the location is ',n um2str(maxloc)]) disp(['The min relative error is ',num2str(minrel),' and the location is ',n um2str(relminloc)]) disp(['The max relative error is ',num2str(maxrel),' and the location is ',n um2str(relmaxloc)]) elseif a==2 %using polyfit and polyval to find the best fit coeff=polyfit(x,y,b); yline=polyval(coeff,x); %find abs error absolute_error=abs(y-yline); %filter data to find the rel error p=1; for i=1:length(x) if y(i)~=0 relative_error(p)=abs((y(i)-yline(i))/y(i)); p=p+1; end end %calculate r^2 SSE=sum(absolute_error.^2); SST=sum((y-sum(y)/length(y)).^2); r2=1-SSE/SST; gtext(['r^2=',num2str(r2)]) disp(['R^2=',num2str(r2)]) %find the max , min and location of abs error and rel error minabs=absolute_error(1); maxabs=absolute_error(1); minrel=relative_error(1); maxrel=relative_error(1); minloc=1; maxloc=1; relminloc=1; relmaxloc=1; for i= 1:length(x) if absolute_error(i)maxabs maxabs=absolute_error(i); maxloc=i; end end for i=1:length(relative_error) if relative_error(i)maxrel maxrel=relative_error(i); relmaxloc=i; end end disp(['The min absolute error is ',num2str(minabs),' and the location is ',n um2str(minloc)]) disp(['The max absolute error is ',num2str(maxabs),' and the location is ',n um2str(maxloc)]) disp(['The min relative error is ',num2str(minrel),' and the location is ',n um2str(relminloc)]) disp(['The max relative error is ',num2str(maxrel),' and the location is ',n um2str(relmaxloc)]) elseif a==3 disp('Spline can not compute errors') elseif a==4 %filt data and finf the ln(y) n=length(x); j=1; for i=1:n if y(i)>0 xfilt(j)=x(i); yfilt(j)=log(y(i));
More Less

Related notes for ENGR 0011
Me

OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Join to view

OR

By registering, I agree to the Terms and Privacy Policies
Just a few more details

So we can recommend you notes for your school.