Presentation is loading. Please wait.

Presentation is loading. Please wait.

ENGR-25_Plot_Model-4.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Registered Electrical.

Similar presentations


Presentation on theme: "ENGR-25_Plot_Model-4.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Registered Electrical."— Presentation transcript:

1 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Registered Electrical & Mechanical Engineer BMayer@ChabotCollege.edu Engr/Math/Physics 25 Chp6 MATLAB Regression

2 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 2 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Learning Goals cont

3 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 3 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Learning Goals cont  Build Math Models for Physical Data using “n th ” Degree Polynomials  Use MATLAB’s “Basic Fitting” Utility to find Math models for Plotted Data

4 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 4 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Scatter on Plots in XY-Plane  A scatter plot usually shows how an EXPLANATORY, or independent, variable affects a RESPONSE, or Dependent Variable  Sometimes the SHAPE of the scatter reveals a relationship  Shown Below is a Conceptual Scatter plot that could Relate the RESPONSE to some EXCITITATION

5 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 5 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Linear Fit by Guessing  The previous plot looks sort of Linear  We could use a Ruler to draw a y = mx+b line thru the data  But which Line is BETTER? and WHY?

6 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 6 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Least Squares Curve Fitting  In a Previous Example polyfit(x,y,1) returned the Values of m & b How does PolyFit Make these Calcs? How Good is the fitted Line Compared to the Data?  polyfit, as do most other curve fitters, uses the “Least Squares” Criterion

7 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 7 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Least Squares  To make a Good Fit, MINIMIZE the |GUESS − data| distance by one of data Best Guess-y Best Guess-x

8 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 8 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Least Squares cont  MATLAB polyfit Minimizes the VERTICAL distances; i.e.:  Note that The Function J contains two Variables; m & b  Recall from MTH1 that to MINIMIZE a Function set the 1 st (partial) Derivative(s) equal to Zero

9 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 9 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Least Squares cont  To Minimize J, take  The Two Partials yield Two LINEAR Eqns in m & b  The two eqns can be solved EXACTLY for m & b  the Book on pg 271 gives a good example  Remember, at this point m & b are UNKNOWN xy 02 56 1011

10 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 10 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Least Squares cont  In This Case  Solving these Eqns for m & b yields m = 9/10 b = 11/6  This produces the best fit Line  Taking ∂J/∂m = 0, and ∂J/∂b = 0 yields xy 02 56 1011

11 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 11 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Goodness of Fit  The Distance from The Best-Fit Line to the Actual Data Point is called the RESIDUAL  For the Vertical Distance the Residual is just δy  If the Sum of the Residuals were ZERO, then the Line would Fit Perfectly  Thus J, after finding m & b, is an Indication of the Goodness of Fit

12 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 12 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Goodness of Fit cont  Now J is an indication of Fit, but we Might want to SCALE it relative to the MAGNITUDE of the Data For example consider –DataSet1 with x&y values in the MILLIONS –DataSet2 with x&y values in the single digits In this case we would expect J1 >> J2  To remove the affect of Absolute Magnitude, Scale J against the Data Set mean; e.g mean1 = 730 000 mean2 = 4.91

13 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 13 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Goodness of Fit cont  The Mean-Scaling Quantity is the Actual-Data Relative to the Actual-Mean  Finally the Scaled Fit-Metric, “r-squared’  As before the Squaring Ensures that all Terms in the sum are POSITIVE

14 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 14 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods r 2 = Coeff of Determination  The r 2 Value is Also Called the COEFFICIENT OF DETERMINATION J  Sum of Residual (errors) –May be Zero or Positive S  Data-to-Mean Scaling Factor –Always Positive if >1 Data-Pt and data not “perfectly Horizontal”  If J = 0, then there is NO Distance Between the calculated Line and Data  Thus if J = 0, then r 2 = 1; so r 2 = 1 (or 100%) indicates a PERFECT FIT

15 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 15 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Meaning of r 2  The COEFFICIENT OF DETERMINATION  Has This Meaning The coefficient of determination tells you what proportion of the variation between the data points is explained or accounted for by the best line fitted to the points. It indicates how close the points are to the line.

16 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 16 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Norm of Residuals  MATLAB uses the Norm of Residuals as a Measure of Goodness of Fit  The Norm of Residuals, N R, is simply the SqRt of J:  Thus r 2 in Terms of N R :  As a Measure of Goodness of Fit as the FIT Approaches Perfection J→0 so:

17 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 17 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods N R vs r 2 →  Notice that r 2 is a RELATIVE Measure → it’s NORMALIZED to the WORST CASE Value of J which is S Thus r 2 can be expressed at PERCENTAGE withOUT Units  N R is an ABSOLUTE measure that Technically Requires that it be stated with SAME UNITS as the dependent variable, y

18 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 18 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Data Scaling  Data-Scaling is a SubTopic of DIMENSIONAL ANALYIS (DA) DA is Covered in 3 rd Yr ME/CE Courses –I Learned it in a Fluid Mechanics Course  For Our Purposes we will cover only SCALING  Sometimes we Collect Data with a SMALL Variation Relative to the Magnitude of the MEAN Leads to a SENSITIVE Analysis; e.g. This Data is Noisy During Analysis xy 89747313 89717309 89697310

19 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 19 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Data Scaling - Normalization  The Significance of ANY Data Set Can be Improved by Normalizing  Normalize  Scale Data such that the Values run: 0 →1 0% → 100%  Steps to Normalization 1.Find the MAX & MIN values in the Data Set; e.g., z max & z min 2.Calculate the Data Range, R D R D = (z max – z min ) 3.Calc the Individual Data Differences Relative to the MIN Δz k = z k - z min

20 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 20 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Data Scaling – Normailzation cont 4.Finally, Scale the Δz k relative to R D Ψ k = Δz k /R D 5.Scale the corresponding “y” values in the Same Manner to produce say, Φ k 6.Plot Φ k vs Ψ k on x & y scales that Run from 0→1  Example – Do Frogs Croak More on WARM Nites? Temperature (ºF) Croaks/Hr 88.620.0 71.616.0 93.319.8 84.318.4 80.617.1 75.215.5 69.714.7 82.017.1 69.415.4 83.316.2 78.615.0 82.617.2 80.616.0 83.517.0 76.314.1

21 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 21 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Normalization Example  Normalize T → Θ CPH → Ω  Now Compare Plots CPH vs T Ω vs Θ

22 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 22 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Plots Compared  T-CPH Plot  Ω-Θ Plot The Θ-Ω Plot Fully Utilizes Both Axes

23 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 23 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Basic Fitting  Use MATLAB’s AutoMatic Fitting Utility to Find The Best Line for the the Frog Croaking Data SEE: Demo_Frog_Croak_BasicFit_1110.m

24 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 24 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods All Done for Today Croaking Frog

25 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 25 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege.edu Engr/Math/Physics 25 Appendix

26 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 26 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Linear Regression Tutorial  Minimize Height Error δy  See File ENGR- 25_Linear_Regressi on_Tutorial_1309.pp tx

27 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 27 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

28 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 28 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Altitude of Right Triangle  The Area of RIGHT Triangle  The Area of an ARBITRARY Triangle  By Pythagoras for Rt-Triangle

29 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 29 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Altitude of Right Triangle cont  Solving for h  Equating the A=½·Base·Hgt noting that

30 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 30 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Normalized Plot >> T = [69.4, 69.7, 71.6, 75.2, 76.3, 78.6, 80.6, 80.6, 82, 82.6, 83.3, 83.5, 84.3, 88.6, 93.3]; >> CPH = [15.4, 14.7, 16, 15.5, 14.1, 15, 17.1, 16, 17.1, 17.2, 16.2, 17, 18.4, 20, 19.8]; >> Tmax = max(T); >> Tmin = min(T); >> CPHmax = max(CPH); >> CPHmin = min(CPH); >> Rtemp = Tmax - Tmin; >> Rcroak = CPHmax - CPHmin; >> DelT = T - Tmin; >> DelCPH = CPH - CPHmin; >> Theta = DelT/Rtemp;DelCPH = CPH - CPHmin; >> Omega = DelCPH/Rcroak; >> plot(T, CPH,), grid >> plot(Theta,Omega), grid

31 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 31 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Start Basic Fitting Interface 1  FIRST → Plot the DATA

32 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 32 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Start Basic Fitting Interface 2 Expand Dialog Box Goodness of Fit; smaller is Better

33 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 33 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Start Basic Fitting Interface 3  Result  Chk by polyfit >> p = polyfit(Theta,Ome ga,1) p = 0.8737 0.0429 

34 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 34 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Caveat

35 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 35 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Greek Letters in Plots

36 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 36 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Plot “Discoverables”

37 BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 37 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods % "Discoverable" Functions Displayed % Bruce Mayer, PE ENGR25 15Jul09 % x = linspace(-5, 5); ye = exp(x); ypp = x.^2; ypm = x.^(-2); % plot all 3 on a single graphe plot(x,ye, x,ypp, x,ypm),grid,legend('ye', 'ypp', 'ypm') disp('Showing MultiGraph Plot - Hit ANY KEY to continue') pause % % PLot Side-by-Side subplot(1,3,1) plot(x,ye), grid subplot(1,3,2) plot(x,ypp), grid subplot(1,3,3) plot(x,ypm), grid


Download ppt "ENGR-25_Plot_Model-4.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Registered Electrical."

Similar presentations


Ads by Google