Download presentation
Presentation is loading. Please wait.
Published byClaud Shields Modified over 9 years ago
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 Fcn Discovery
2
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 2 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Learning Goals Create “Linear-Transform” Math Models for measured Physical Data Linear Function → No Xform Power Function → Log-Log Xform Exponential Function → SemiLog Xform Build Math Models for Physical Data using “n th ” Degree Polynomials Use MATLAB’s “Basic Fitting” Utility to find Math models for Plotted Data
3
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 3 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Learning Goals Use Regression Analysis as quantified by the “Least Squares” Method Calculate –Sum-of-Squared Errors (SSE or J) The Squared Errors are Called “Residuals” –“Best Fit” Coefficients –Sum-of-Squares About the Mean (SSM or S) –Coefficient of Determination (r 2 ) Scale Data if Needed –Creates more meaningful spacing
4
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 4 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 Use MATLAB to Produce 3-Dimensional Plots, including Surface Plots Contour Plots
5
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 5 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Function Discovery Physical Processes for some Response (OutPut), y, as Resulting from some Excitation (InPut), x, can many times be approximated by 3 Functions 1.The LINEAR function: y = mx + b –Produces a straight line with SLOPE a of m and an INTERCEPT of b when plotted on rectilinear axes 2.The POWER function: y = bx m –gives a straight line when plotted on log-log axes 3.The exponential function y = b·10 mx or y = b·e mx –Yields a straight line when plotted on a semilog plot with logarithmic y-axis
6
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 6 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Linear Transformations For a Linear Function We can Easily Find the Slope, m, and y-Intercept, b Transform the Power Function to Line-Like Form Take ln of both sides
7
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 7 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Power Function Xform Thus the Power Function Takes the Form: Yields a Staight Line So if we suspect a PwrFcn, Plot the Data in Log-Log Form Example: If The Data Follows the Power Function Then a Plot of
8
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 8 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Power Function y = 13x 1.73 Rectlinear Plot Log-Log Plot
9
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 9 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods y = 13x 1.73 by MATLAB loglog >> x = linspace(7, 91, 500); >> y = 13*x.^1.73; >> loglog(x,y), xlabel('x'), ylabel('y'), title('y = 13x^1^.^7^3'), grid
10
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 10 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Exponential Function Xform Recall the General form of the Exponential Fcn In This Case Let Then the Xformed Exponential Fcn Again taking the ln A SemiLog (log-y) plot Should Show as a Straight Line
11
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 11 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Exponential Fcn Plot Plot Rectlinear Plot SemiLog Plot
12
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 12 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods V = 115e -0.61t by MATLAB semilogy >> t = linspace(0, 10, 500); >> v = 115*exp(- 0.61*t); semilogy(t,v), xlabel('t'), ylabel('v'), title('v = 115e^- ^0^.^6^1^t'), grid
13
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 13 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Steps for Function Discovery 1.Examine the data near the origin. The linear function can pass through the origin only if b = 0 The exponential function (y = be mx ) can never pass through the origin –as e t > 0 (positive) for ALL t; e.g., e −2.7 = 0.0672 –unless of course b = 0, which is a trivial case: y = 0·e mx The power function (y = bx m ) can pass through the origin (e.g.; y = 7x 3 ) but only if m > 0 (positive) as –As y = bx -m = b/x m → Hyperbolic for negative m
14
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 14 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods “Discoverable” Functions In most applications x is NONnegative
15
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 15 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Steps for Function Discovery 2.Plot the data using rectilinear scales. If it forms a straight line, then it can be represented by the linear function and you are finished. Otherwise, if you have data at x = 0, then a.If y(0) = 0, then try the power function. b.If y(0) 0, then try the exponential function c.If data is not given for x = 0, then proceed to step 3.
16
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 16 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Steps for Function Discovery 3.If you suspect a power function, then plot the data using log-log scales. Only a power function will form a straight line on a log-log plot. 4.If you suspect an exponential function, then plot the data using the SemiLogy scale. Only an exponential function will form a straight line on a SemiLog plot.
17
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 17 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods SemiLog and LogLog Scales Note Change in power Function x-axis scales –In this case x MUST be POSITIVE
18
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 18 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Steps for Function Discovery 5.In function discovery applications, use the log-log and semilog plots only to identify the function type, but not to find the coefficients b and m. The reason is that it is difficult to interpolate on log scales To Determine Quantities for m & b Perform the Appropriate Linearization Transform to plot one of –ln(y) vs. ln(x) → Power Fcn –ln(y) vs x → Exponential Fcn
19
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 19 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods The polyfit Function The Command → p = polyfit(x,y,n) This Function Fits a polynomial of degree n to data described by the vectors x and y, where x is the independent variable. polyfit Returns a row vector p of length n + 1 that contains the polynomial coefficients in order of descending powers Note That a FIRST Degree Polynomial Describes the Eqn of a LINE If w =p 1 z +p 2 then polyfit on data Vectors W & Z returns: p = ployfit(Z,W,1) = [p 1, p 2 ] → [m, b]
20
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 20 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Using polyfit For Discovery polyfit of degree-1 ( n = 1 ) returns the parameters of a Line p 1 → m (slope) p 2 → b (intercept) Thus polyfit can provide m & b for any of the previously noted functions AFTER the appropriate Linearization Transform
21
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 21 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods m & b by polyfit(x,y,1) We need to find an Eqn for the Vapor pressure of Ethanol, C 2 H 5 OH, as a fcn of Temperature Find P v vs T Data by Consulting P. E. Liley and W. R. Gambill, Chemical Engineers’ HandBk, New York, McGraw- Hill Inc., 1973, p. 3-34 & 3-54 P v for Ethanol (Torr) Temperature (Kelvins) 760351.4 400336.5 200321.4 100307.9 60299 40292 20281 10270.7 5261 1241.7
22
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 22 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods m & b by polyfit(x,y,1) cont Since this a Vapor Pressure we Suspect an Antoine or Clapeyron Relation P v ~ e m/T As a Starting Point Make a Rectilinear Plot >> Pv = [1, 5, 10, 20, 40, 60, 100, 200, 400, 760]; >> T = [241.7, 261, 270.7, 281, 292, 299, 307.9, 321.4, 336.5, 351.4]; >> plot(T,Pv,'x', T,Pv,':'), xlabel('T (K)'), ylabel('Pv (Torr)'),... title('Ethanol Vapor Pressure'), grid
23
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 23 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Compare LogLog vs SemiLogY Log Log Plot logY vs linX Looks like an Exponential in 1/T e.g., the Clapeyron eqn
24
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 24 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods m & b by polyfit(x,y,1) cont The Plots Looks Pretty Well Exponential For a 1 st -Cut Assume the Clapeyron form Now Xform Thus Plot ln(P v ) vs 1/T
25
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 25 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods m & b by polyfit(x,y,1) cont The Command Session Nicely Linear → Clapeyron is OK >> Ye = log(Pv); >> x = 1./T >> plot(x,Ye,'d', x,Ye,':'), xlabel('1/T (1/K)'), ylabel('ln(Pv) (ln(Torr))'),... title('Ethanol Vapor Pressure - Clapeyron Plot'), grid
26
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 26 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods m & b by polyfit(x,y,1) cont Apply PolyFit to Find m and B >> p = polyfit(x,Ye,1) p = 1.0e+003 * -5.1304 0.0213 or To Increase the Sig Figs displayed for B these plots are typically plotted with x1 = 1000/T >> x1 = 1000./T >> p1 = polyfit(x1,Ye,1) p1 = -5.1304 21.2512
27
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 27 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods m & b by polyfit(x,y,1) cont
28
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 28 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods All Done for Today Power and Exps
29
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 29 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege.edu Engr/Math/Physics 25 Appendix
30
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 30 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Power Fcn Plot >> x =[7:91]; >> y = 13*x.^1.73; >> Xp = log(x); >> Yp = log(y); >> plot(x,y), xlabel('x'), ylabel('y'),... grid, title('Power Function') >> plot(Xp,Yp), xlabel('ln(x)'), ylabel('ln(y)'),... grid, title('Power Function')
31
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 31 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Exponential Fcn Plot >> t = [0:0.05:10]; >> v = 120*exp(-0.61*t); >> plot(t,v), xlabel('t'), ylabel('v'),... grid, title('Exponential Function') >> Ve = log(v); >> plot(t,Ve), xlabel('t'), ylabel('ln(v)'),... grid, title('Exponential Function')
32
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 32 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
33
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 33 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Altitude of Right Triangle cont Solving for h Equating the A=½·Base·Hgt noting that
34
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 34 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
35
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 35 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Start Basic Fitting Interface 1 FIRST → Plot the DATA
36
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 36 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Start Basic Fitting Interface 2 Expand Dialog Box Goodness of Fit; smaller is Better
37
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 37 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
38
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 38 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Caveat
39
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 39 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Greek Letters in Plots
40
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 40 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Plot “Discoverables”
41
BMayer@ChabotCollege.edu ENGR-25_Plot_Model-4.ppt 41 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.