40
[email protected] • ENGR-25_Lec-20_Statistics-2.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical & Mechanical Engineer [email protected] Engr/Math/Physics 25 Chp7 Statistics-2

Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

  • Upload
    ayala

  • View
    17

  • Download
    0

Embed Size (px)

DESCRIPTION

Engr/Math/Physics 25. Chp7 Statistics-2. Bruce Mayer, PE Licensed Electrical & Mechanical Engineer [email protected]. Learning Goals. Create HISTOGRAM Plots Use MATLAB to solve Problems in Statistics Probability Use Monte Carlo (random) Methods to Simulate Random processes - PowerPoint PPT Presentation

Citation preview

Page 1: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt1

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Bruce Mayer, PELicensed Electrical & Mechanical Engineer

[email protected]

Engr/Math/Physics 25

Chp7Statistics-

2

Page 2: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt2

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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

Page 3: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt3

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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 (often uniform; often not)• Numbers are obtained completely by chance • They have nothing to do with the

other numbers in the sequence Uniform distribution → each possible

number is equally probable

Page 4: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt4

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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 (ri

2 = 68376361) • ri+2 = 1601 (ri+1

2 = 14160169)• ri+3 = 6320 (ri+2

2 = 2563201)

Page 5: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt5

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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

algorithmic operation have their own built-in characteristics• MATLAB uses a 35 Element “seed”

Page 6: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt6

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Random Number CommandsCommand Description

Rand Generates a single uniformly distributed random number between 0 and 1.

rand(n) Generates an nX?n matrix containing uniformly distributed random numbers between 0 and 1.

rand(m,n) Generates an mX?n matrix containing uniformly distributed random numbers between 0 and 1.

s = rand(’state’) Returns a 35-element vector s containing the current state of the uniformly distributed generator.

rand(’state’,s) Sets the state of the uniformly distributed generator to s.

rand(’state’,0) Resets the uniformly distributed generator to its initial state.

rand(’state’,j) Resets the uniformly distributed generator to state j, for integer j.

rand(’state’,sum(100*clock)) Resets the uniformly distributed generator to a different state each time

Page 7: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt7

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Some (psuedo)Random No.s0.30253 0.35572 0.8678 0.065315 0.98548 0.62339 0.50921 0.762670.85184 0.049047 0.37218 0.2343 0.017363 0.68589 0.07429 0.72180.75948 0.75534 0.07369 0.9331 0.81939 0.67735 0.19324 0.651640.94976 0.89481 0.19984 0.063128 0.62114 0.87683 0.3796 0.754020.55794 0.28615 0.049493 0.26422 0.56022 0.012891 0.27643 0.66316

0.014233 0.2512 0.56671 0.99953 0.24403 0.3104 0.77088 0.883490.59618 0.93274 0.12192 0.21199 0.82201 0.77908 0.31393 0.272160.81621 0.13098 0.52211 0.49841 0.26321 0.3073 0.63819 0.419430.97709 0.94082 0.11706 0.29049 0.75363 0.92668 0.98657 0.212990.22191 0.70185 0.76992 0.67275 0.65964 0.67872 0.50288 0.03560.70368 0.84768 0.37506 0.95799 0.21406 0.074321 0.9477 0.0811640.52206 0.20927 0.82339 0.76655 0.60212 0.070669 0.82803 0.85057

0.9329 0.45509 0.046636 0.66612 0.60494 0.01193 0.91756 0.34020.71335 0.081074 0.59791 0.13094 0.6595 0.22715 0.11308 0.466150.22804 0.85112 0.94915 0.095413 0.18336 0.51625 0.81213 0.913760.44964 0.56205 0.2888 0.014864 0.63655 0.4582 0.90826 0.22858

0.1722 0.3193 0.88883 0.28819 0.17031 0.7032 0.15638 0.862040.96882 0.3749 0.10159 0.81673 0.5396 0.58248 0.12212 0.65662

MATLAB Command → RandTab2 = rand(18,8);

Page 8: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt8

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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

Page 9: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt9

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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

Page 10: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt10

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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.

Page 11: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt11

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Monte Carlo Process Steps1. Define the System2. Generate (psuedo)Random No.s3. 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

Page 12: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt12

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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

Page 13: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt13

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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 (UCB)

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

Page 14: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt14

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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

Page 15: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt15

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

MATLAB RANDOM No. PDFs MATLAB rand

command produces RNs with a Uniform Distribution• i.e., ANY Value

over [0,1] just as likely as Any OTHER

MATLAB randn, by Contrast, produces a NORMAL Distribution• i.e., The MIDDLE

Value is MORE Likely than any other

Page 16: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt16

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Scaling rand 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]

axaby

>> y =(37-19)*rand + 19

Example: Use rand to Produce Uniformly Dist Random No over [19,37]

>> y =(37-19)*rand + 19y = 36.1023>> y =(37-19)*rand + 19y = 23.1605

• Example Result

Page 17: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt17

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Scaled & Offset Random No.s

33.0445 28.8462 30.5977 24.5998 20.5393 19.6793 19.5497 20.073126.0153 24.3338 25.8150 35.6208 23.7247 34.9330 32.3933 31.275523.3504 32.4045 33.6084 26.7437 33.4183 35.4392 28.0004 19.763826.2704 22.4012 28.5909 22.3267 19.5260 33.3313 27.6386 20.286020.7362 31.3620 25.3131 35.2879 35.7194 20.7768 35.2850 28.389721.3755 22.3032 35.9020 36.6355 32.1460 23.7137 29.9776 20.741135.9569 25.6327 34.7670 26.8997 27.7950 25.0364 30.1180 33.726736.2104 30.2611 28.9028 21.0001 29.4135 31.2351 34.4700 33.715829.3538 33.0441 30.2046 23.6452 23.2711 21.4580 33.4988 32.003920.0760 20.4603 29.5668 26.3570 27.2593 31.9821 29.3810 21.697623.2260 35.7289 22.7394 29.7081 36.3356 20.9217 22.2926 30.872925.3569 32.9628 24.4224 23.7198 28.8425 30.7676 23.3188 28.334733.7815 27.7622 27.4766 29.8512 28.3804 27.8951 34.9572 36.513519.2773 26.8455 23.1488 31.8019 23.1687 33.0229 19.5161 30.681819.7744 27.0421 34.1976 22.9914 27.8002 31.8707 27.8182 33.406022.0418 24.5143 22.5058 21.1135 30.2331 35.2670 22.0227 27.168430.6841 28.1532 23.0666 24.3402 31.2244 35.0366 36.6163 26.783032.1710 28.1939 22.0727 24.7380 26.1193 25.0149 31.8285 33.855630.6594 33.7173 23.0980 26.6350 25.6139 31.5774 28.0085 20.502527.1166 33.3070 26.8426 28.1414 36.7837 22.5606 27.4796 21.3971

rand1937 = (37-19)*rand(20,8) + 19

>> Rmax =max(max(rand1937))Rmax = 36.7837

>> Rmin = min(min(rand1937))Rmin = 19.2773

Page 18: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt18

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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

prvw

>> w =(2.3)*randn - 17

Example: Use randn to Produce Normal Dist with µ = –17 & σ = 2.3

>> w =(2.3)*randn - 17w = -20.8308>> w =(2.3)*randn - 17w = -16.7117

• Example Result

Page 19: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt19

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

rand vs randn – scaled and offset rand

0 10 20 30 40 50 60 70 80 90 1000

20

40

60

80

100

120

140rand

RN100 = 100*rand(10000,1);hist(RN100,100), title('rand')

randn

Norm100 = 100*randn(10000,1) + 100hist(Norm100,100), title('randn')

-300 -200 -100 0 100 200 300 400 5000

50

100

150

200

250

300

350randn

Page 20: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt20

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Monte Carlo Example (1) Build a Wharehouse from PreCast

Concrete (a Tilt-Up) Per PERT Chart

1. Project Start

2

3

4 5 6 7 1. Project End

A B

C D

E F G H

PERT Program Evaluation and Review Technique• A Scheduling Tool Developed for

the USA Space Program

Page 21: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt21

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Monte Carlo Example (2)

1. Project Start

2

3

4 5 6 7 1. Project End

A B

C D

E F G H

In This Case The Schedule ElementsE. Install PreCast Parts

on FoundationF. Build RoofG. Finish Interior

and ExteriorH. Inspect Result

A. Excavate FoundationB. Construct FoundationC. Fabricate PreCast

ComponentsD. Ship PreCast Parts

to Building Site

Page 22: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt22

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Monte Carlo Example (3) Task Durations → Normal Random Variables

• Assume Normally DistributedTask

ID Task Description Mean Duration(days)

Std Dev(days)

A Foundation Excavation 3.5 1B Pour Foundation 2.5 0.5C Fab PreCast Elements 5 1D Ship PreCast Parts 0.5 0.5E Tilt-Up PreCast Parts 5 1.5F Roofing 2 1G Finish Work 4 1

Expected Duration = 17 Days

Page 23: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt23

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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

GFEDCBAtbld ,max

Early GATE

Page 24: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt24

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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.741.77 2.29 4.39 0.86 5.51 2.88 4.14 17.783.35 2.46 5.29 1.08 6.21 0.64 4.06 17.293.28 2.79 4.70 1.07 4.73 0.53 4.70 16.033.94 2.78 4.31 0.92 1.64 3.10 4.00 15.461.89 1.89 5.21 0.61 3.49 1.55 4.70 15.563.04 2.52 5.80 0.95 5.21 0.38 3.18 15.513.93 2.13 5.56 -0.19 5.69 2.63 4.19 18.572.49 2.33 5.44 -0.30 3.95 0.92 4.50 14.525.23 2.85 4.25 0.61 4.66 1.15 4.17 18.073.61 1.93 4.32 0.36 5.98 0.75 3.70 15.983.02 2.99 6.76 1.21 6.37 2.33 4.03 20.712.00 2.29 4.98 0.61 3.49 1.34 4.28 14.702.31 2.11 5.27 1.27 3.42 2.63 3.60 16.193.19 2.20 6.26 0.93 1.84 1.64 4.28 14.951.94 2.40 4.57 0.75 3.69 2.08 3.74 14.832.09 2.31 4.54 0.35 4.55 0.41 4.55 14.404.82 2.44 4.26 0.61 4.40 2.06 3.12 16.855.19 2.66 5.72 1.30 1.90 1.26 4.09 15.104.03 2.22 5.30 -0.11 4.72 1.70 4.48 17.14

Run-1• µ = 16.27

Days• σ = 1.61

Days

See some Negative Durations!• May want

to Adjust

Page 25: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt25

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Monte Carlo Example (6) Run-2

• µ = 16.99 Days

• σ = 2.05Days

Task-A Task-B Task-C Task-D Task-E Task-F Task-G Task SUM2.79 2.26 3.02 0.77 3.67 1.86 4.56 15.134.98 1.59 6.63 0.99 3.18 -0.79 4.08 14.102.12 2.76 3.46 0.00 5.11 1.34 3.95 15.283.47 2.76 7.77 0.63 5.84 -1.10 4.73 17.851.94 2.43 4.26 0.05 6.85 2.49 4.46 18.162.87 3.33 3.37 0.28 4.18 1.21 3.56 15.165.40 2.73 6.02 0.50 5.12 3.51 3.76 20.513.40 2.26 4.49 0.46 4.32 0.44 4.57 15.003.73 2.13 6.29 0.69 2.79 1.63 4.14 15.544.45 2.21 5.34 -0.23 4.73 2.45 3.92 17.763.44 1.80 7.21 1.30 3.41 2.03 3.89 17.843.92 2.69 5.49 0.11 2.87 2.43 4.18 16.083.42 3.27 5.75 -0.14 6.65 2.88 4.75 20.983.32 2.70 4.39 1.09 5.56 1.25 3.84 16.673.75 2.85 4.44 0.76 4.73 2.89 4.38 18.594.16 2.62 4.64 -0.07 3.92 0.79 4.63 16.112.52 2.43 6.39 0.87 3.08 0.61 3.41 14.363.61 2.51 4.06 0.00 6.38 1.49 3.78 17.764.16 2.49 3.24 0.00 7.21 1.98 4.60 20.454.16 1.40 4.27 0.85 3.47 3.00 4.53 16.56

Page 26: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt26

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Monte Carlo Example (7) The

MATLAB Script File

% Bruce Mayer, PE • ENGR25 • 25Oct11% Normal Dist Task Duration on PERT Chart% file = Monte_Carlo_Wharehouse.m

% % 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 Modelfor 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)

Page 27: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt27

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Monte Carlo Example (8) Just for Fun Try 1000 Random

Simulation Cycles

µ1000 = 17.3730 days• Expected 17

σ1000 = 2.1603 days• Expected 2.1794 by RMS calc

1. Project Start

2

3

4 5 6 7 1. Project End

A B

C D

E F G H

Page 28: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt28

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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

Page 29: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt29

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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

Page 30: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt30

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Linear Interpolation (3) Then the Linear Interpolation Eqn

lohi

loact

lohi

loint

xxxx

yyyy

A Proportionality, 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

Page 31: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt31

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Linear InTerp PorPortionality

lohi

loact

lohi

loint

xxxx

yyyy

i.e.; yint−ylo is to yhi−ylo

AS xact−xlo is to xhi−xlo

Page 32: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt32

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

InTerp Pt-Slope Line Eqn It’s LINEAR as the Interp

Eqn can be cast into the familiar Point-Slope Eqn

ReWorking the Interp Equation

11 xxmyy

loactlohi

lohiloint

lohi

loact

lohi

loint xxxxyyyy

xxxx

yyyy

loactxlointlohi

lohix xxmyy

xxyym

actact

Let

The LOCAL slope evaluated about xact

Page 33: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt33

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Linear Interpolation Example From the Rockwell Tester Manual

67.3

xlo

xhi yhi

ylo

The InterpEqn

135.36070603.67

5.30.35.3

intint yy

Page 34: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt34

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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

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.

zint = interp2(x,y,z,xint,yint)

interp2 Does Linear Interp in 2D

Page 35: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt35

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

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

Page 36: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt36

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

INterp vs. Extrap Graphically

Interpolation

Extrapolation

Known Data ENDS

Page 37: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt37

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Cubic Spline Interpolation If the Data

exhibits significant CURVATURE, MATLAB can Interpolate with Curves as well using the spline form

Linear

Spline Curveyint = 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

Page 38: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt38

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

All Done for Today

Considerthe

Source Most Engineering Data is NOT Sufficiently ACCURATE nand/nor PRECISE to Justify Anything But LINEAR Interpolation

Page 39: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt39

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Bruce Mayer, PELicensed Electrical & Mechanical Engineer

[email protected]

Engr/Math/Physics 25

Appendix 6972 23 xxxxf

Page 40: Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege

[email protected] • ENGR-25_Lec-20_Statistics-2.ppt40

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Random No. Table