Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Engr/Math/Physics 25 Chp7 Statistics-2 Bruce Mayer, PE Licensed Electrical & Mechanical Engineer [email protected] Engineering/Math/Physics 25: Computational Methods 1 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Learning Goals Create HISTOGRAM Plots Use MATLAB to solve Problems in • Statistics • Probability Use Monte Carlo (random) Methods to Simulate Random processes Properly Apply Interpolation to Estimate values between or outside of know data points Engineering/Math/Physics 25: Computational Methods 2 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Random Numbers (RNs) There is no such thing as a ‘‘random number” • is 53 a random number? (need a Sequence) Definition: a SEQUENCE of statistically INDEPENDENT numbers with a Defined DISTRIBUTION (usually uniform) • Numbers are obtained by chance • They have nothing to do with the other numbers in the sequence Uniform distribution → each possible number is equally probable Engineering/Math/Physics 25: Computational Methods 3 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Random Number Generator von Neumann (ca. 1946) Developed the Middle Square Method take the square of the previous number and extract the middle digits example: four-digit numbers • • • • ri = 8269 ri+1 = 3763 (ri2 = 68376361) ri+2 = 1601 (ri+12 = 14160169) ri+3 = 6320 (ri+22 = 2563201) Engineering/Math/Physics 25: Computational Methods 4 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt PSUEDO-Random Number Most Computer Based Random Number Generators are Actually PSUEDO-Random in implementation Note that for the von Nueman Method • Each number is COMPLETELY determined by its predecessor • The sequence is NOT random but appears to be so statistically → pseudo-random numbers All random number generators based on an arithmetic operation have their own built-in characteristics • MATLAB uses a 35 Element “seed” Engineering/Math/Physics 25: Computational Methods 5 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Random Number Commands Command Rand rand(n) rand(m,n) s = rand(’state’) rand(’state’,s) rand(’state’,0) rand(’state’,j) rand(’state’,sum(100*clock)) Engineering/Math/Physics 25: Computational Methods 6 Description Generates a single uniformly distributed random number between 0 and 1. Generates an nX? n matrix containing uniformly distributed random numbers between 0 and 1. Generates an mX? n matrix containing uniformly distributed random numbers between 0 and 1. Returns a 35-element vector s containing the current state of the uniformly distributed generator. Sets the state of the uniformly distributed generator to s. Resets the uniformly distributed generator to its initial state. Resets the uniformly distributed generator to state j, for integer j. Resets the uniformly distributed generator to a different state each time Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Some (psuedo)Random No.s 0.30253 0.35572 0.8678 0.065315 0.98548 0.62339 0.85184 0.049047 0.37218 0.2343 0.017363 0.68589 0.75948 0.75534 0.07369 0.9331 0.81939 0.67735 0.94976 0.89481 0.19984 0.063128 0.62114 0.87683 0.55794 0.28615 0.049493 0.26422 0.56022 0.012891 0.014233 0.2512 0.56671 0.99953 0.24403 0.3104 0.59618 0.93274 0.12192 0.21199 0.82201 0.77908 0.81621 0.13098 0.52211 0.49841 0.26321 0.3073 0.97709 0.94082 0.11706 0.29049 0.75363 0.92668 0.22191 0.70185 0.76992 0.67275 0.65964 0.67872 0.70368 0.84768 0.37506 0.95799 0.21406 0.074321 0.52206 0.20927 0.82339 0.76655 0.60212 0.070669 0.9329 0.45509 0.046636 0.66612 0.60494 0.01193 0.71335 0.081074 0.59791 0.13094 0.6595 0.22715 0.22804 0.85112 0.94915 0.095413 0.18336 0.51625 0.44964 0.56205 0.2888 0.014864 0.63655 0.4582 0.1722 0.3193 0.88883 0.28819 0.17031 0.7032 0.96882 0.3749 0.10159 0.81673 0.5396 0.58248 0.50921 0.76267 0.07429 0.7218 0.19324 0.65164 0.3796 0.75402 0.27643 0.66316 0.77088 0.88349 0.31393 0.27216 0.63819 0.41943 0.98657 0.21299 0.50288 0.0356 0.9477 0.081164 0.82803 0.85057 0.91756 0.3402 0.11308 0.46615 0.81213 0.91376 0.90826 0.22858 0.15638 0.86204 0.12212 0.65662 MATLAB Command → RandTab2 = rand(18,8); Engineering/Math/Physics 25: Computational Methods 7 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Random No. Simulation Started During WWII for the purpose of Developing Inexpensive methods for testing engineered systems by IMITATING their Real Behavior These Methods are Usually called MONTE CARLO Simulation Techniques Engineering/Math/Physics 25: Computational Methods 8 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Monte Carlo Simulation (1) The Basis for These Methods • Develop a Computer-Based Analytical Model, or Equation/Algorithm, that (hopefully) Predicts System Behavior • The Model is then Evaluated Many Times to Produce a STATISTICAL PROBABILITY for the System Behavior • Each Evaluation (or Simulation) Cycle is based on Randomly-Set Values for System Input/Operating Parameters Engineering/Math/Physics 25: Computational Methods 9 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Monte Carlo (2) • Analytical Tools are Used to ensure that the Random assignment of Input Parameter Values meet the Desired Probability Distribution Function The Result of MANY Random Trials Yields a Statistically Valid Set of Predictions • Then Use standard Stat Tools to Analyze Result to Pick the “Best” Overall Value – e.g.: Mean, Median, Mode, Max, Min, etc. Engineering/Math/Physics 25: Computational Methods 10 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Monte Carlo Process Steps 1. Define the System 2. Generate (psuedo)Random No.s 3. Generate Random VARIABLES • Usually Involves SCALING and/or OFFSETTING the RNs 4. Evaluate the Model N-Times; each time using Different Random Vars 5. Statistical Analysis of the N-trial Results to assess Validity & Values Engineering/Math/Physics 25: Computational Methods 11 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Monte Carlo System The System Definition Should Include • Boundaries (Barriers that don’t change) • Input Parameters • Output (Behavior) Parameters • Processes (Architecture) that Relate the Input Parameters to the Output Parameters Engineering/Math/Physics 25: Computational Methods 12 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Fixed Model Architecture The Model is assumed to be Unvarying; i.e., it behaves as a Math FUNCTION Example: SPICE • SPICE ≡ Simulation Program with Integrated Circuit Emphasis SPICE has Monte Carlo BUILT-IN Engineering/Math/Physics 25: Computational Methods 13 SPICE uses • UNchanging Physical Laws KVL & KCL • IDEAL Circuit Elements I/V Sources, R, C, L Component VALUES for R, L, C, Vs, and Q can Vary Randomly Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Monte Carlo Summarized Monte Carlo Method: Probabilistic simulation technique used when a process has a random component 1. Identify a Probability Distribution Function (PDF) 2. Setup intervals of random numbers to match probability distribution 3. Obtain the random numbers 4. Interpret the results Engineering/Math/Physics 25: Computational Methods 14 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt MATLAB RANDOM No. PDFs MATLAB rand command produces RNs with a Uniform Distribution MATLAB randn, by Contrast, produces a NORMAL Distribution • i.e., ANY Value over [0,1] just as likely as Any OTHER • i.e., The MIDDLE Value is MORE Likely than any other Engineering/Math/Physics 25: Computational Methods 15 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Scaling rand rand covers the interval [0,1] – To cover [a,b] SCALE & OFFSET the Random No. Example: Use rand to Produce Uniformly Dist Random No over [19,37] • Let x be a random >> y =(37-19)*rand + 19 No. over [0,1], then a • Example Result random number y >> y =(37-19)*rand + 19 over [a,b] y b a x a Engineering/Math/Physics 25: Computational Methods 16 y = 36.1023 >> y =(37-19)*rand + 19 y = 23.1605 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt rand vs randn – scaled and offset rand randn rand randn 140 350 120 300 100 250 80 200 60 150 40 100 20 50 0 0 10 20 30 40 50 60 70 80 90 RN100 = 100*rand(10000,1); hist(RN100,100), title('rand') Engineering/Math/Physics 25: Computational Methods 17 100 0 -300 -200 -100 0 100 200 300 400 500 Norm100 = 100*randn(10000,1) + 100 hist(Norm100,100), title('randn') Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Scaling randn randn Produces a Normal Dist. with µ = 0, and σ = 1 • Let v be a normal random No. with µ=0 & σ=1, then a random number w with µ=p&σ=r w rv p Engineering/Math/Physics 25: Computational Methods 18 Example: Use randn to Produce Normal Dist with µ = –17 & σ = 2.3 >> w =(2.3)*randn - 17 • Example Result >> w =(2.3)*randn - 17 w = -20.8308 >> w =(2.3)*randn - 17 w = -16.7117 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Monte Carlo Example (1) Build a Wharehouse from PreCast Concrete (a Tilt-Up) Per PERT Chart A 2 B E 1. Project Start 4 C 3 F 5 G 6 H 1. Project End 7 D PERT Program Evaluation and Review Technique • A Scheduling Tool Developed for the USA Space Program Engineering/Math/Physics 25: Computational Methods 19 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Monte Carlo Example (2) A 2 B E 1. Project Start 4 C 3 F 5 G 6 H 7 1. Project End D In This Case The Schedule Elements A. Excavate Foundation B. Construct Foundation C. Fabricate PreCast Components D. Ship PreCast Parts to Building Site Engineering/Math/Physics 25: Computational Methods 20 E. Install PreCast Parts on Foundation F. Build Roof G. Finish Interior and Exterior H. Inspect Result Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Monte Carlo Example (3) Task Durations → Normal Random Variables • Assume Normally Distributed Task ID Task Description Mean Duration Std Dev (days) (days) A Foundation Excavation 3.5 1 B Pour Foundation 2.5 0.5 C Fab PreCast Elements 5 1 D Ship PreCast Parts 0.5 0.5 E Tilt-Up PreCast Parts 5 1.5 F Roofing 2 1 G Finish Work 4 1 Expected Duration = 17 Days Engineering/Math/Physics 25: Computational Methods 21 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Monte Carlo Example (4) Analytical Model • Foundation-Work and PreCasting Done in PARALLEL – One will be The GATING Item before Tilt-Up • Other Tasks Sequential Mathematical Model tbld max A B, C D E F G Early GATE Engineering/Math/Physics 25: Computational Methods 22 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Monte Carlo Example (5) Task-A Task-B Task-C Task-D Task-E Task-F Task-G Task-Sum 4.82 2.47 6.32 0.61 2.86 1.85 3.75 15.74 1.77 2.29 4.39 0.86 5.51 2.88 4.14 17.78 3.35 2.46 5.29 1.08 6.21 0.64 4.06 17.29 3.28 2.79 4.70 1.07 4.73 0.53 4.70 16.03 3.94 2.78 4.31 0.92 1.64 3.10 4.00 15.46 1.89 1.89 5.21 0.61 3.49 1.55 4.70 15.56 3.04 2.52 5.80 0.95 5.21 0.38 3.18 15.51 3.93 2.13 5.56 -0.19 5.69 2.63 4.19 18.57 2.49 2.33 5.44 -0.30 3.95 0.92 4.50 14.52 5.23 2.85 4.25 0.61 4.66 1.15 4.17 18.07 3.61 1.93 4.32 0.36 5.98 0.75 3.70 15.98 3.02 2.99 6.76 1.21 6.37 2.33 4.03 20.71 2.00 2.29 4.98 0.61 3.49 1.34 4.28 14.70 2.31 2.11 5.27 1.27 3.42 2.63 3.60 16.19 3.19 2.20 6.26 0.93 1.84 1.64 4.28 14.95 1.94 2.40 4.57 0.75 3.69 2.08 3.74 14.83 2.09 2.31 4.54 0.35 4.55 0.41 4.55 14.40 4.82 2.44 4.26 0.61 4.40 2.06 3.12 16.85 5.19 2.66 5.72 1.30 1.90 1.26 4.09 15.10 4.03 2.22 5.30 -0.11 4.72 1.70 4.48 17.14 Engineering/Math/Physics 25: Computational Methods 23 Run-1 • µ = 16.27 Days • σ = 1.61 Days See some Negative Durations! • May want to Adjust Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Monte Carlo Example (6) Task-A Task-B Task-C Task-D Task-E Task-F Task-G Task SUM 15.13 4.56 1.86 3.67 0.77 3.02 2.26 2.79 14.10 4.08 -0.79 3.18 0.99 6.63 1.59 4.98 15.28 3.95 1.34 5.11 0.00 3.46 2.76 2.12 17.85 4.73 -1.10 5.84 0.63 7.77 2.76 3.47 18.16 4.46 2.49 6.85 0.05 4.26 2.43 1.94 15.16 3.56 1.21 4.18 0.28 3.37 3.33 2.87 20.51 3.76 3.51 5.12 0.50 6.02 2.73 5.40 15.00 4.57 0.44 4.32 0.46 4.49 2.26 3.40 15.54 4.14 1.63 2.79 0.69 6.29 2.13 3.73 17.76 3.92 2.45 4.73 -0.23 5.34 2.21 4.45 17.84 3.89 2.03 3.41 1.30 7.21 1.80 3.44 16.08 4.18 2.43 2.87 0.11 5.49 2.69 3.92 20.98 4.75 2.88 6.65 -0.14 5.75 3.27 3.42 16.67 3.84 1.25 5.56 1.09 4.39 2.70 3.32 18.59 4.38 2.89 4.73 0.76 4.44 2.85 3.75 16.11 4.63 0.79 3.92 -0.07 4.64 2.62 4.16 14.36 3.41 0.61 3.08 0.87 6.39 2.43 2.52 17.76 3.78 1.49 6.38 0.00 4.06 2.51 3.61 20.45 4.60 1.98 7.21 0.00 3.24 2.49 4.16 16.56 4.53 3.00 3.47 0.85 4.27 1.40 4.16 Engineering/Math/Physics 25: Computational Methods 24 Run-2 • µ = 16.99 Days • σ = 2.05 Days Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Monte Carlo Example (7) % Program Demo_Monte_Carlo_WhareHouse % Normal Dist Task Duration on PERT Chart % Bruce Mayer, PE ENGR25 27Sep05 % % Use 20 Random No.s for Simulation % Set 20-Val Row-Vectors for Task Durations % for k = 1:20; tA(k) = 1*randn + 3.5; tB(k) = 0.5*randn + 2.5; tC(k) = 1*randn + 5; tD(k) = 0.5*randn + 0.5; tE(k) = 1.5*randn + 5; tF(k) = 1*randn + 2; tG(k) = 0.5*randn + 4; end % % Calc Simulated Durations per Model for k = 1:20; tSUM(k) = max((tA(k)+tB(k)),(tC(k)+tD(k)))+tE(k)+tF(k)+tG(k); end % % Put into Table for Display Purposes % t_tbl =[tA',tB',tC',tD',tE',tF',tG',tSUM'] % tmu = mean(tSUM) The MATLAB Script File Engineering/Math/Physics 25: Computational Methods 25 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Monte Carlo Example (8) Just for Fun Try 1000 Random Simulation Cycles A 2 B E 1. Project Start 4 C 3 F 5 G 6 H 7 1. Project End D µ1000 = 17.3730 days • Expected 17 σ1000 = 2.1603 days • Expected 2.345 by RMS calc Engineering/Math/Physics 25: Computational Methods 26 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Linear Interpolation (1) During a Hardness Testing Lab in ENGR45 we measure the HRB at 67.3 on a ½” Round Specimen The Rockwell Tester was Designed for FLAT specimens, so the Instruction manual includes a TABLE for ADDING an amount to the Round-Specimen Measurement to Obtain the CORRECTED Value Engineering/Math/Physics 25: Computational Methods 27 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Linear Interpolation (2) From the Rockwell Tester Manual 67.3 • To Apply LINEAR interpolation Need to Find Only the Data Surrounding: – The Independent (Measured) Variable – The Corresponding Dependent Variable Values Engineering/Math/Physics 25: Computational Methods 28 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Linear Interpolation (3) Then the Linear Interpolation Eqn yint ylo xact xlo yhi ylo xhi xlo Where • xact actual MEASURED value • yint Unknown INTERPOLATED value • xlo TABULATED Value Just Below xact • xhi TABULATED Value Just Above xact • ylo TABULATED Value Corresponding to xlo • yhi TABULATED Value Corresponding to xhi Engineering/Math/Physics 25: Computational Methods 29 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Linear InTerp PorPortionality yint ylo xact xlo yhi ylo xhi xlo i.e.; yint−ylo is to yhi−ylo AS xact−xlo is to xhi−xlo Engineering/Math/Physics 25: Computational Methods 30 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Linear Interpolation Example From the Rockwell Tester Manual 67.3 The Interp Eqn xlo ylo xhi yhi yint 3.5 67.3 60 yint 3.135 3.0 3.5 70 60 Engineering/Math/Physics 25: Computational Methods 31 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Linear Interp With MATLAB Use the interp1 Command to find yint >> Xtab = [60, 70]; % = [xlo, xhi] >> Ytab = [3.5, 3.0]; % = [ylo, yhi] >> yint = interp1(Xtab, Ytab, 67.3) yint = 3.1350 Engineering/Math/Physics 25: Computational Methods 32 interp2 Does Linear Interp in 2D zint = interp2(x,y,z,xint,yint) Used to linearly interpolate a function of two variables: z f (x, y). Returns a linearly interpolated vector zint at the specified values xint and yint, using (tabular) data stored in x, y, and z. Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Interpolation vs Extrapolation Class Q: Who can Explain the DIFFERENCE? INTERpolation Estimates Data Values between KNOWN Discrete Data Points • Usually Pretty Good Estimate as we are within the Data “Envelope” EXTRApolation PROJECTS Beyond the Known Data to Predict Additional Values • Much MORE Uncertainty in Est. value Engineering/Math/Physics 25: Computational Methods 33 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt INterp vs. Extrap Graphically Extrapolation Known Data ENDS Interpolation Engineering/Math/Physics 25: Computational Methods 34 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Cubic Spline Interpolation If the Data exhibits significant CURVATURE, MATLAB can Interpolate with Curves as well using the spline form Linear Spline Curve yint = spline(x,y,xint) Computes a cubic-spline interpolation where x and y are vectors containing the data and xint is a vector containing the values of the independent variable x at which we wish to estimate the dependent variable y. The result yint is a vector the same size as xint containing the interpolated values of y that correspond to xint Engineering/Math/Physics 25: Computational Methods 35 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt All Done for Today Consider the Source Engineering/Math/Physics 25: Computational Methods 36 Most Engineering Data is NOT Sufficiently ACCURATE nand/nor PRECISE to Justify Anything But LINEAR Interpolation Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Engr/Math/Physics 25 Appendix f x 2 x 7 x 9 x 6 3 2 Bruce Mayer, PE Licensed Electrical & Mechanical Engineer [email protected] Engineering/Math/Physics 25: Computational Methods 37 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt Random No. Table Engineering/Math/Physics 25: Computational Methods 38 Bruce Mayer, PE [email protected] • ENGR-25_Lec-20_Statistics-2.ppt