Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
1 HOMEWORK 3 STAT 305A Spring 2017 Due 2/23(R) SOLUTION PROBLEM 1 (35pts) [See book Problem 5-55 on p.183] In an acid-base titration, a base or acid is gradually added to the other until they have completely neutralized each other. Let X and Y denote (the act of measuring) the milliliters of 120 5 2 , acid and base, respectively, needed for equivalence. Assume that ( X , Y ) ~ N 100 XY XY . 2 2 (a)(5pts) For XY 0.6 find XY . Solution: XY XY XY XY XY X Y 0.6(5)( 2) 6 (b)(5pts) Find Pr[ X 116] . Solution: Pr[ X 116] = normcdf(116,120,5) = 0.2119 ml. (c)(10pts) Find Pr[ X 116 | Y 102] . [Hint: See book p.182.] Solution: X 5 ( y Y ) 120 0.6 (102 100) 123 and 2 Y 2 X2 (1 XY ) 52 (1 0.62 ) 16 . So X | Y 2 ~ N (123,4 2 ) . From p.182 we have X |Y y X XY X2 |Y y Hence, Pr[ X 116 | Y 102] = normcdf(116,123,4) = 0.0401 (d)(5pts) Find Pr[ X 118 Y 96] . To this end, write a Matlab code that uses the Matlab command ‘mvncdf’. Solution: M=[120,100]; C=[25,6;6,4]; X=[118,96]; Prd=mvncdf(X,M,C) Ans: Prd = 0.0203 y (e)(10pts) Find Pr[118 X 122 96 Y 104] . To this end, (i) show the event as a shaded area in an x-y plot. Then (ii) write a Matlab code that uses 104 the Matlab command ‘mvncdf’. Include your code HERE. 96 Solution: p1=mvncdf([122,104],M,C); p2=mvncdf([122,96],M,C); x 122 118 p3=mvncdf([118,104],M,C); p4=mvncdf([118,96],M,C); %This area was counted twice Figure 1(e) Plot showing the event. Pre=p1-p2-p3+p4 Ans: Pre = 0.3066 NOTE: You can also use mvncdf([118,96],[122,104],M,C) WOW! All in just ONE command. But- the simplicity of this command can prevent one from gaining a better understanding of the cdf concept. Beware! 2 PROBLEM 2 (40pts) In relation to PROBLEM 1, assume that, in truth, ( X , Y ) has the bivariate normal distribution given in PROBLEM 1. (a)(5pts) Write a Matlab code that will simulate n 100 measurements of ( X , Y ) , and then produce a scatter plot of the resulting data. Solution: [See code under 2(a) in Appendix] xy=mvnrnd(M,C,25); x=xy(:,1); y=xy(:,2); figure(21) plot(x,y,'*') grid Figure 2(a) Scatter plot for n 100 [Grader: I am including code here for your benefit.] (b)(5pts) From your data in (a) obtain an estimate of XY 0.6 . Then compute the percent error of your estimate. Solution: R=corrcoef(xy); rhoXYhat=R(1,2); rhoXYhat = 0.6314 . e 100(.6314 .6) / .6 5.23% R=corrcoef(xy); rhoXYhat=R(1,2) (c)(10pts) Use your data to obtain a linear prediction model Y mX b . The overlay this model on a scatter plot of the data. Aslo, give the numerical values of your m and b . Solution: [See code under 2(c) in Appendix] [mhat bhat] = [ 0.2347 71.8097 ] Mhat=mean(xy); Chat=cov(xy); mhat=Chat(1,2)/Chat(1,1); bhat=Mhat(2)-mhat*Mhat(1); yhat=mhat*x + bhat; hold on plot(x,yhat,'r','LineWidth',2) Figure 2(c) Scatter plot for n 100 and prediction line. (d)(10pts) Use 104 simulations to arrive at the pdf for the estimator m . Also, give the numerical values of m and m . Solution: [See code under 2(d) in Appendix] m 0.2402 , m 0.0326 mhat=zeros(1,nsim); bhat=zeros(1,nsim); for k=1:nsim Code in (c) with m & b replaced by m(k) & b(k) end [hm,bm]=hist(mhat,50); dbm=(bm(2)-bm(1));fmhat=hm/(nsim*dbm); figure(23); bar(bm,fmhat); grid; xlabel('m-value'); title('PDF for mhat'); mu_mhat=mean(mhat);std_mhat=std(mhat); [mu_mhat , std_mhat] [NOTE: n=25 was used in Spring 2016! I changed to n=100.] Figure 2(d) PDF for m using sample size n 100 . (e)(5pts) Compute the true value of m. Then comment on how it compares to your value for m in (d). Solution: m XY / X2 6 / 52 0.2400 . This is almost exactly m 0.2407 . (f)(5pts) Assume that m ~ N (0.24 , 0.07 2 ) . Find Pr[0.23 m 0.25] Solution: Pre=normcdf(.25,.24,.07) - normcdf(.23,.24,.07) Pre = 0.1136 3 PROBLEM 3 (25pts) A press fit refers to fitting two parts together, so as to ensure that they will not slip relative to one another. From https://en.wikipedia.org/wiki/Interference_fit we have the following example: A 10 mm (0.394 in) shaft made of 303 stainless steel will form a tight fit with allowance of 3–10 µm (0.0001–0.0003 in). A slip fit can be formed when the bore diameter is 12–20 µm (0.0005–0.0008 in) wider than the rod. Suppose that shafts are machined to conform to a shaft diameter distribution S ~ N ( S 10mm , S ) and the bores are machined to conform to a bore diameter distribution B ~ N ( B 10.0065mm , B ) . Denote the clearance between the shaft and bore as C B S . (a)(3pts) Use the linearity of E(*) to arrive at C in units of m . Solution: C E (C ) E ( B S ) E ( B) E ( S ) 10.0065 10.0000 0.0065 mm 6.5 m . (b)(2pts) Suppose we require that C 1 m . From this constraint, obtain an expression for B2 as a function of S2 . Solution: Because we are given no covariance information, we will assume that B and S are independent. Then 2 2 C2 1 S2 B2 . Hence, B 1 S . (c)(5pts) Suppose that the shaft machining cost as a function of S is T ( S ) 1 / S ($) and the bore machining cost as a function of B is T ( B ) 3 / B ($). Then the total cost of a shaft/bore unit is Ttot T ( S ) T ( B ) (1 / S ) (3 / B ) . From this cost function, along with the constraint you found in (b), one can use the method of Lagrange multipliers [ https://en.wikipedia.org/wiki/Lagrange_multiplier ] to show that the total cost will be minimized for S 0.5700 m and B 0.8218 m . Rather than using this elegant mathematical method, proceed to arrive at these numbers as follows: (i) define the Matlab array S 0.1 : 0.001 : 0.9 (ii) create your B array per your constraint in (b) (iii) compute your Ttot array per the above equation (iv) use the command [Tmin , k0 ] min( Ttot ) to find the minimum cost and the associated array index, and (v) recover your values of S (k 0 ) and B (k 0 ) . Include your code and answers HERE. Solution: min( Ttot ) = $5.4056 ; S =0.5700 um Code: sigS=0.1:0.001:0.9; [Tmin,k0]=min(T); ; B = 0.8216 um sigB=sqrt(1-sigS.^2); T=sigS.^-1 + 3*sigB.^-1; [Tmin , sigS(k0) , sigB(k0)] (d)(10pts) Suppose that one of your colleagues claims that the company has been using S B 1 m for ages, and it is still in business. Hence, to change to the tighter specifications you are suggesting in (c) is simply a waste of money. In this part compute the probability that the clearance will not be in the range 3 10 m for both his specs. and yours. Solution: From (b): C ~ N (6.5m ,1m) . So My failure prob. = p1=normcdf(3,6.5,1) + (1-normcdf(10,6.5,1))= 4.6526e-04 Using C 12 12 2 m his is p2=normcdf(3,6.5,sqrt(2)) + (1-normcdf(10,6.5,sqrt(2))) = 0.0133 (e)(5pts) Compute the total cost of a shaft/bore pair using his numbers. Then use your answers in (c) and (d) to compute the anticipated cost of lost units in a run of 10,000 bore/shaft pairs of using your specs. and his. Solution: His cost is Ttot (1 / S ) (3 / B ) (1 / 1) (3 / 1) $4.00 . For a run of 10,000 units: Using my specs. we could anticipate ~5 failed units for a total cost of 5 $5.42 $27 Using his specs we could anticipate 133 failed units for a total cost of 133 $4.00 $532 (20x my cost!) 4 Matlab Code %PROGRAM NAME: hw4.m clear all %PROBLEM 1: %1(d) M=[120,100]; C=[25,6;6,4]; X=[118,96]; Prd=mvncdf(X,M,C) %1(e): p1=mvncdf([122,104],M,C); p2=mvncdf([122,96],M,C); p3=mvncdf([118,104],M,C); p4=mvncdf([118,96],M,C); Pre=p1-p2-p3+p4 %PROBLEM 2: %2(a): n=100; xy=mvnrnd(M,C,n); x=xy(:,1); y=xy(:,2); figure(21) plot(x,y,'*') grid xlabel('Acid Amount (x)') ylabel('Base Amount (y)') %2(b): R=corrcoef(xy); rhoXYhat=R(1,2) %2(c): Mhat=mean(xy); Chat=cov(xy); mhat=Chat(1,2)/Chat(1,1); bhat=Mhat(2)-mhat*Mhat(1); yhat=mhat*x + bhat; hold on plot(x,yhat,'r','LineWidth',2) %2(d): nsim=10^4; mhat=zeros(1,nsim); bhat=zeros(1,nsim); for k=1:nsim xy=mvnrnd(M,C,100); x=xy(:,1); y=xy(:,2); Mhat=mean(xy); Chat=cov(xy); mhat(k)=Chat(1,2)/Chat(1,1); bhat(k)=Mhat(2)-mhat(k)*Mhat(1); end [hm,bm]=hist(mhat,50); dbm=(bm(2)-bm(1)); fmhat=hm/(nsim*dbm); figure(23) bar(bm,fmhat) grid xlabel('m-value') title('PDF for mhat') mu_mhat=mean(mhat); std_mhat=std(mhat); [mu_mhat , std_mhat]