This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 4/17/09 10:26 PM C:\Documents and Settings\Kevin Haas\My Documents\cla...\hw8_2.m 1 of 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % problem 8.2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear clc %Input the speed x x=[40 9 100 50 15 65 25 60 95 60 30 125]; %Input the stopping distance y y=[15 2 40 15 4 25 5 25 30 24 8 45]; N=length(x); %Sort the values from lowest to highest [x ind]=sort(x); y=y(ind); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Part (a) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% figure(1) clf plot(x,y, 'x' , 'markersize' ,12, 'linewidth' ,2) xlabel( 'Speed (kph)' ) ylabel( 'Stopping distance (m)' ) grid on %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Part (b) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Find the means and standard deviations xbar=mean(x); s_x=std(x); ybar=mean(y); s_y=std(y); %Find the regression coefficients xy=x.*y; x2=x.*x; beta=(sum(xy)N*xbar*ybar)/(sum(x2)N*xbar^2) alpha=ybarbeta*xbar %Regression values yprime yp=alpha+beta*x; %Plot the regression line figure(1) hold on plot(x,yp, 'r' , 'linewidth' ,2) %Find the conditional variance s2yx=1/(N2)*sum((yyp).^2); syx=sqrt(s2yx) %Find the correlation coefficient rho=beta*s_x/s_y %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Part (c) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Find the critical value for 10% with 10 dof t_crit=1.8125; %Find the confidence interval 4/17/09 10:26 PM C:\Documents and Settings\Kevin Haas\My Documents\cla...\hw8_2.m 2 of 2 conf=t_crit*syx*sqrt(1/N+(xxbar).^2/sum((xxbar).^2)); %Plot the conf interval figure(1) hold on plot(x,yp+conf, 'k' ,x,ypconf, 'k' , 'linewidth' ,1.5) legend( 'data' , 'yprime' , 'confidence' , 'location' , 'NW' ) 20 40 60 80 100 120 14010 10 20 30 40 50 Speed (kph) Stopping distance (m) data yprime confidence 4/17/09 10:25 PM MATLAB Command Window 1 of 1 beta = 0.3863 alpha =1.8611 syx = 2.8049 rho = 0.9819 >> 4/17/09 10:40 PM C:\Documents and Settings\Kevin Haas\My Documents\cla...\hw8_4.mC:\Documents and Settings\Kevin Haas\My Documents\cla....
View
Full Document
 Spring '09
 Haas
 Normal Distribution, Standard Deviation, Variance, energy consumption, xlabel, Settings\Kevin Haas\My Documents\cla

Click to edit the document details