Random Signals for Engineers using MATLAB and Mathcad Copyright 1999 Springer Verlag NY Example 3.3 Moments of Continuous Distributions In this example we will derive relationships for the expected values for three distributions, the uniform, exponential and gaussian and give examples of their use. UNIFORM - A train is expected to arrive between the hours of 1 and 4 PM. We assume a uniform distribution of arrival time in the 1 - 4 interval. What is the expected arrival time of the train and what is the variance? SOLUTION: The problem can be solved by computing the expected value of a uniform distribution with f(x) = 1 / (4 - 1) for 1 < x < 4 or 4 1 E X u du 3 1 syms x u Ex=int(u/3,u,1,4) Ex = 5/2 We derive a general formula for a rectangular distribution syms a b Ex=int(u/(b-a),u,a,b) Ex = -1/2*b^2/(-b+a)+1/2*a^2/(-b+a) Ex= simplify(Ex); pretty(Ex) 1/2 a + 1/2 b The second moment may be similarly computed Ex2=int(u^2/(b-a),u,a,b) Ex2= simplify(Ex2) Ex2 = -1/3*b^3/(-b+a)+1/3*a^3/(-b+a) Ex2 = 1/3*a^2+1/3*b*a+1/3*b^2 The variance can be computed using the formula for moments Equation 3.2-5 VAR[X] = E[X2] - E[X]2 = VARx=Ex2-Ex^2 VARx=simplify(VARx) VARx = 1/3*a^2+1/3*b*a+1/3*b^2-(1/2*a+1/2*b)^2 VARx = 1/12*a^2-1/6*b*a+1/12*b^2 factoring the expression we obtain VARx=factor(VARx) VARx = 1/12*(-b+a)^2 The last simplification was performed by Matlab using simplify and factor. The solution to the train arrival problem is therefore subs(Ex,{a,b},{1,4}) ans = 2.5000 subs(VARx,{a,b},{1,4}) ans = 0.7500 sqrt(0.75)*60 ans = 51.9615 minutes The expected hour of arrival is 2.5 or 2:30 PM with a variance of 0.75 hours 2. It is customary to use the root of the variance since the units are the same as the expected values. We restate the results as the train is expected to arrive at 2:30 PM with a standard deviation of sqrt((0.75)60 = 52 minutes. EXPONENTIAL - A lifetime of a part in hours follows an exponential distribution with a parameter = 0.1. What is the expected lifetime of the part what is the variance of the lifetime? SOLUTION: The problem can be solved by computing the expected value of a exponential distribution with f t e t for 0 < t < or syms lam gt = sym('lam>0'); maple('assume',gt); ET=int(u*lam*exp(-lam*u),u,0,inf) ET = 1/lam In the solution of the integral, Maple evaluated the integral with n as the upper limit. Then the limit was taken when n and we obtained E[T] = 1 / . The parameter has been shown to be the reciprocal of the expected lifetime. The variance can be similarly computed by computing the second moment and using Equation 3.4-5 ET2=int(u^2*lam*exp(-lam*u),u,0,inf) ET2 = 2/lam^2 In the solution of the integral, Maple evaluated the integral with n as the upper limit. Then the limit was taken when n and we obtained E[T2]= 2 / 2. The variance is VAR[T] = E[T 2] - E[T]2 = VART=ET2-ET^2; VART=simplify(VART) VART = 1/lam^2 The solution to the lifetime problem is subs(ET,lam,0.1) ans = 10 hours VAR[T] = subs(VART,lam,0.1) ans = 100.0000 hours2 GAUSSIAN - For the gaussian distribution we will demonstrate the normalization factor = 1 and identify the two parameters, a and 2, of the distribution as the mean and variance of the distribution, respectively. Equation 2.5-8 shows the normalization factor of the integral, I, 2 for the gaussian. We begin by setting up the kernel syms sig u v f=exp(-1/2*u^2) f = exp(-1/2*u^2) g=subs(f,u,v); pretty(f) 2 exp(- 1/2 u ) The integral I cannot be directly evaluated. Let us instead find an expression for I 2. We must changes variables to avoid confusion in the dummy variables of the two integrals I2= int(int(f*g,u,-inf,inf),v,-inf,inf); double(1/(2*pi)*I2) ans = 1 Using Matlab we find that the integral for I2 is indeed equal to unity. We can show the details of the computation by expanding the integral and changing variable. syms u v syms r alp fg=f*g; pretty(fg) 2 2 exp(- 1/2 u ) exp(- 1/2 v ) Let u = r cos() and v = r sin() and dv du = r dr d to maintain the same elemental area of integration we have u2 + v2 = r2. The limits of the area integral have to be change to encompass the same area and 0 2 and 0 < r < . Rewriting the integral we have er=subs(fg,{u,v},{r*cos(sig) r*sin(sig)}); er=simple(er) er = exp(-1/2*r^2) u=r*cos(alp); v=r*sin(alp); J= det(jacobian([u ; v],[r alp])); J=simple(J) J = r 1 I 2 2 2 r e 0 1 r 2 2 dr d 0 This two-dimensional integral is separable and each integral can be evaluated separately, The integral for r is found by Matlab and is equal to unity. int(er*J,r,0,inf) ans = 1 The other integral for evaluates to 2 , which is exactly equal to the square of the normalizing factor. maple('int','1,x=0..2*pi') ans = 2*pi The expected value is computed by the integral after we clear the symbols u and v so that they can reused in another context. syms u unreal syms v unreal clear u v syms a u v f=u*exp(-1/2*((u-a)/sig)^2) f = u*exp(-1/2*(u-a)^2/sig^2) syms sig gt= sym('sig>0'); maple('assume',gt); EXG=1/sig*int(f,u,-inf,inf) EXG = a*2^(1/2)*pi^(1/2) The result must be divided by 2 to obtain E[X] for a gaussian = a. The integral may also be evaluated by first substituting for v = (u - a)/ and dv = du / . The integral becomes EXG=int(exp(-1/2*v^2)*(sig*v+a),v,-inf,inf) EXG = a*2^(1/2)*pi^(1/2) for the same result. The second moment and the variance is similarly computed E[X2] = EX2G=int(exp(-1/2*v^2)*(sig*v+a)^2,v,-inf,inf); EX2G=simple(EX2G) EX2G = 2^(1/2)*pi^(1/2)*(a^2+sig^2) Again we must normalize by dividing by 2 to obtain E[X2] = a2 +2. The variance is therefore, using Equation 3.4- 5, VAR[X] = 2. We have shown that the two parameters of the gaussian are the mean = a and the variance = and is called the standard deviation.