380 likes | 488 Views
Engr/Math/Physics 25. Chp7 Statistics-2. Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege.edu. Learning Goals. Create HISTOGRAM Plots Use MATLAB to solve Problems in Statistics Probability Use Monte Carlo (random) Methods to Simulate Random processes
E N D
Engr/Math/Physics 25 Chp7Statistics-2 Bruce Mayer, PE Licensed Electrical & Mechanical EngineerBMayer@ChabotCollege.edu
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
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
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)
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”
Some (psuedo)Random No.s MATLAB Command → RandTab2 = rand(18,8);
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
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
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.
Monte Carlo Process Steps • Define the System • Generate (psuedo)Random No.s • Generate Random VARIABLES • Usually Involves SCALING and/or OFFSETTING the RNs • Evaluate the Model N-Times; each time using Different Random Vars • Statistical Analysis of the N-trial Results to assess Validity & Values
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
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 • 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
Monte Carlo Summarized • Monte Carlo Method: Probabilistic simulation technique used when a process has a random component • Identify a Probability Distribution Function (PDF) • Setup intervals of random numbers to match probability distribution • Obtain the random numbers • Interpret the results
MATLAB rand command produces RNs with a Uniform Distribution i.e., ANY Value over [0,1] just as likely as Any OTHER MATLAB RANDOM No. PDFs • MATLAB randn, by Contrast, produces a NORMAL Distribution • i.e., The MIDDLE Value is MORE Likely than any other
rand covers the interval [0,1] – To cover [a,b] SCALE & OFFSET the Random No. Let x be a random No. over [0,1], then a random number y over [a,b] Scaling rand • Example: Use rand to Produce Uniformly Dist Random No over [19,37] >> y =(37-19)*rand + 19 • Example Result >> y =(37-19)*rand + 19 y = 36.1023 >> y =(37-19)*rand + 19 y = 23.1605
rand rand vs randn – scaled and offset • randn RN100 = 100*rand(10000,1); hist(RN100,100), title('rand') Norm100 = 100*randn(10000,1) + 100 hist(Norm100,100), title('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 Scaling randn • 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
2 1. Project Start 1. Project End 4 5 6 7 3 Monte Carlo Example (1) • Build a Wharehouse from PreCast Concrete (a Tilt-Up) Per PERT Chart A B E F G H D C • PERT Program Evaluation and Review Technique • A Scheduling Tool Developed for the USA Space Program
2 1. Project Start 1. Project End 4 5 6 7 3 Monte Carlo Example (2) A B E F G H D C • In This Case The Schedule Elements • Install PreCast Parts on Foundation • Build Roof • Finish Interior and Exterior • Inspect Result • Excavate Foundation • Construct Foundation • Fabricate PreCast Components • Ship PreCast Parts to Building Site
Monte Carlo Example (3) • Task Durations → Normal Random Variables • Assume Normally Distributed
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 Early GATE
Monte Carlo Example (5) • Run-1 • µ = 16.27 Days • σ = 1.61Days • See some Negative Durations! • May want to Adjust
Monte Carlo Example (6) • Run-2 • µ = 16.99 Days • σ = 2.05Days
The MATLAB Script File 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)
2 1. Project Start 1. Project End 4 5 6 7 3 Monte Carlo Example (8) • Just for Fun Try 1000 Random Simulation Cycles A B E F G H D C • µ1000 = 17.3730 days • Expected 17 • σ1000 = 2.1603 days • Expected 2.345 by RMS calc Q.E.F.
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
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
Linear Interpolation (3) • Then the Linear Interpolation Eqn • Where • xact actual MEASURED value • xlo TABULATED Value Just Below xact • xhi TABULATED Value Just Above xact • yint Unknown INTERPOLATED value • ylo TABULATED Value Corresponding to xlo • yhi TABULATED Value Corresponding to xhi
Linear InTerpPorPortionality • i.e.; yint−ylo is to yhi−yloAS xact−xlo is to xhi−xlo
Linear Interpolation Example • From the Rockwell Tester Manual xlo ylo 67.3 xhi yhi • The InterpEqn
Use the interp1 Command to find yint Linear Interp With MATLAB • interp2 Does Linear Interp in 2D >> Xtab = [60, 70]; % = [xlo, xhi] >> Ytab = [3.5, 3.0]; % = [ylo, yhi] >> yint = interp1(Xtab, Ytab, 67.3) yint = 3.1350 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.
Interpolation vsExtrapolation • 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
INterp vs. Extrap Graphically Extrapolation Known Data ENDS Interpolation
If the Data exhibits significant CURVATURE, MATLAB can Interpolate with Curves as well using the spline form Cubic Spline Interpolation 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
All Done for Today ConsidertheSource • Most Engineering Data is NOT Sufficiently ACCURATE nand/nor PRECISE to Justify Anything But LINEAR Interpolation
Engr/Math/Physics 25 Appendix Time For Live Demo Bruce Mayer, PE Licensed Electrical & Mechanical EngineerBMayer@ChabotCollege.edu