Random Signals for Engineers using MATLAB and Mathcad Copyright 1999 Springer Verlag NY Example 2.6 Gaussian Probability Functions In this example we will first plot the gaussian density and distribution function and then examine the use of these functions to solve problems. The gaussian density function is defined using three arguments, the random variable and two parameters and expressed in the gauss_den function f x, a , 1 2 e 1 xa 2 2 The normalized distribution function is computed using the Matlab built in function erf(y). We may verify that indeed that this density function integrated over all - < x < is normalized to unity. The integration is performed using numerical methods and we cannot use ± as the limits of integration. A large value is used instead and values are assigned to a and format long cnormv=quad('gauss_den',-5,5) cnormv = 0.99999937052599 We can notice that with ±5 as limits the value of the integral is close to 1. The integration may be repeated with larger values until 1 is approached at the limit. The density and distribution function can be plotted by first assigning a range of values to the random variable, t function y=gauss_den(t) % gauss_den is the gaussian density function % where a,s = mean and standard deviation % t = variable a=0; s=1; cof=1/sqrt(2*pi*s^2); arg=-((t-a).^2)/(2*s^2); y=cof*exp(arg); t=0:.01:6; ti=t-3; plot(ti,gauss_den(ti)) 0.4 0.35 0.3 0.25 0.2 0.15 0.1 0.05 0 -3 -2 -1 0 1 2 3 The distribution function can similarly be plotted using the cnorm function. By Equation 2.5-11 we have a relationship between cnorm and erf the built in Matlab function. t=0:.01:6; ti=t-3; plot(ti,(erf(ti/sqrt(2))+1)/2) 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 -3 -2 -1 0 1 2 3 PROBLEM: A simple problem illustrates the use of the distribution function in order to compute the probability of a gaussian random variable being less than 5.5. We are told that the distribution function is gaussian with a = 3 and = 2. SOLUTION: First compute y and then find FX(5.5) = P[ X < 5.5] or P[ X < 5.5] = cnorm(y) format short; y=(5.5-3)/2; (erf(y/sqrt(2))+1)/2 ans = 0.8944 Next, we are asked to determine the probability that a machine will fail in t hours and 1000 < t < 3000. We are given that the machines life is gaussian distributed with a = 4000 hours and = 1000 hours. In addition, we would like to know how long it would take before we only have 2% of a group of machines operating. The first probability is computed by defining a function P(x,a,) = (erf((x-a)/(*sqrt(2))+1)/2 = cnorm(x,a,) The problem statement is expressed in term of probability P[1000 < T < 3000] = P[ T < 3000] P[ T < 1000] cnorm(3000,4000,1000) - cnorm(1000,4000,1000) ans = 0.1573 The probability is = 0.157. The time can be computed by setting the P[T < t ] = 0.98 and solving for t. The solve function of Matlab is used to find the nonlinear solution to this equation syms t solve(cnorm(t,4000,1000)-0.98) ans = 6053.7489106318231288361839650872 or 6054 Hours. The functions are listed below. function y=cnorm(x,a,s) % cnorm is the cumulative gaussian function % where a,s = mean and standard deviation % x = variable y=(erf((x-a)/(s*sqrt(2)))+1)/2;