Engr/Math/Physics 25
1 / 41

Bruce Mayer, PE Registered Electrical & Mechanical Engineer [email protected] - PowerPoint PPT Presentation

  • Uploaded on

Engr/Math/Physics 25. Chp6 MATLAB Fcn Discovery. Bruce Mayer, PE Registered Electrical & Mechanical Engineer [email protected] Learning Goals. Create “Linear-Transform” Math Models for measured Physical Data Linear Function → No Xform Power Function → Log-Log Xform

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about ' Bruce Mayer, PE Registered Electrical & Mechanical Engineer [email protected]' - muriel

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Engr/Math/Physics 25

Chp6 MATLABFcn Discovery

Bruce Mayer, PE

Registered Electrical & Mechanical [email protected]

Learning goals
Learning Goals

  • Create “Linear-Transform” Math Models for measured Physical Data

    • Linear Function → No Xform

    • Power Function → Log-Log Xform

    • Exponential Function → SemiLogXform

  • Build Math Models for Physical Data using “nth” Degree Polynomials

  • Use MATLAB’s “Basic Fitting” Utility to find Math models for Plotted Data

Learning goals1
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 (r2)

    • Scale Data if Needed

      • Creates more meaningful spacing

Learning goals cont
Learning Goals cont

  • Build Math Models for Physical Data using “nth” 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

Function discovery

Physical Processes for some Response (OutPut), y, as Resulting from some Excitation (InPut), x, can many times be approximated by 3 Functions

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

The POWER function: y = bxm

gives a straight line when plotted on log-log axes

The exponential function y = b·10mx or y = b·emx

Yields a straight line when plotted on a semilog plot with logarithmic y-axis

Function Discovery

Linear transformations

For a Linear Function We can Easily Find the Slope, m, and y-Intercept, b

Linear Transformations

  • Transform the Power Function to Line-Like Form

  • Take ln of both sides

Power function xform

Thus the Power Function Takes the Form:

Power Function Xform

  • 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

Power function y 13x 1 73

Rectlinear Plot

Log-Log Plot

Power Function y = 13x1.73

Y 13x 1 73 by matlab loglog
y = 13x1.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

Exponential function xform

Recall the General form of the Exponential Fcn

Exponential Function Xform

  • In This Case Let

  • Then the Xformed Exponential Fcn

  • Again taking the ln

  • A SemiLog (log-y) plot Should Show as a Straight Line

Exponential fcn plot


Exponential Fcn Plot

  • SemiLog Plot

  • Rectlinear Plot

V 115e 0 61t by matlab semilog y
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

Steps for function discovery

Examine the data near the origin.

The linear function can pass through the origin only if b = 0

The exponential function (y = bemx) can never pass through the origin

as et > 0 (positive) for ALL t; e.g., e−2.7 = 0.0672

unless of course b = 0, which is a trivial case: y = 0·emx

The power function (y = bxm) can pass through the origin (e.g.; y = 7x3) but only if m > 0 (positive) as

As y = bx-m = b/xm→ Hyperbolic for negative m

Steps for Function Discovery

Discoverable functions
“Discoverable” Functions

  • In most applications x is NONnegative

Steps for function discovery1

Plot the data using rectilinear scales.

If it forms a straight line, then it can be represented by the linear functionand you are finished.

Otherwise, if you have data at x = 0, then

If y(0) = 0, then try the power function.

If y(0)  0, then try the exponential function

If data is not given for x = 0, then proceed to step 3.

Steps for Function Discovery

Steps for function discovery2

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.

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.

Steps for Function Discovery

Semilog and loglog scales
SemiLog and LogLog Scales

  • Note Change in power Function x-axis scales

    • In this case x MUST be POSITIVE

Steps for function discovery3

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

Steps for Function Discovery

The polyfit function

The Command → semilog plots 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 =p1z +p2 then polyfit on data Vectors W & Z returns: p = ployfit(Z,W,1) = [p1, p2] → [m, b]

The polyfit Function

Using polyfit for discovery

polyfit of degree-1 ( semilog plots n = 1) returns the parameters of a Line

p1 → m (slope)

p2 → b (intercept)

Thus polyfit can provide m & b for any of the previously noted functions AFTER the appropriate Linearization Transform

Using polyfit For Discovery

M b by polyfit x y 1

We need to find an Eqn for the Vapor pressure of Ethanol, C semilog plots 2H5OH, as a fcn of Temperature

Find Pv 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

m & b by polyfit(x,y,1)

M b by polyfit x y 1 cont

Since this a Vapor Pressure we Suspect an Antoine or Clapeyron Relation  Pv ~ em/T

As a Starting Point Make a Rectilinear Plot

m & b by polyfit(x,y,1)cont

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

Compare loglog vs semilogy

Log Log Plot Clapeyron Relation

Compare LogLog vs SemiLogY

  • logY vs linX

  • Looks like an Exponential in 1/T

    • e.g., the Clapeyron eqn

M b by polyfit x y 1 cont1

The Plots Looks Pretty Well Exponential Clapeyron Relation

For a 1st-Cut Assume the Clapeyron form

m & b by polyfit(x,y,1)cont

  • Now Xform

  • Thus Plot ln(Pv) vs 1/T

M b by polyfit x y 1 cont2

The Command Session Clapeyron Relation

m & b by polyfit(x,y,1)cont

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

  • Nicely Linear → Clapeyron is OK

M b by polyfit x y 1 cont3

Apply PolyFit to Clapeyron Relation Find m and B

m & b by polyfit(x,y,1)cont

  • To Increase the Sig Figs displayed for B these plots are typically plotted with x1 = 1000/T

>> p = polyfit(x,Ye,1)

p =

1.0e+003 *

-5.1304 0.0213

>> x1 = 1000./T

>> p1 = polyfit(x1,Ye,1)

p1 =

-5.1304 21.2512

  • or

M b by polyfit x y 1 cont4
m & b by Clapeyron Relation polyfit(x,y,1)cont

All done for today
All Done for Today Clapeyron Relation


Engr/Math/Physics 25 Clapeyron Relation


Time For

Live Demo

Bruce Mayer, PE

Licensed Electrical & Mechanical [email protected]

Power fcn plot
Power Fcn Plot Clapeyron Relation

>> 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')

Exponential fcn plot1
Exponential Fcn Plot Clapeyron Relation

>> 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')

Altitude of right triangle

The Area of RIGHT Triangle Clapeyron Relation

Altitude of Right Triangle

  • The Area of an ARBITRARY Triangle

  • By Pythagoras for Rt-Triangle

Altitude of right triangle cont
Altitude of Right Triangle Clapeyron Relation cont

  • Equating the A=½·Base·Hgt noting that

  • Solving for h


Normalized plot
Normalized Plot Clapeyron Relation

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

Start basic fitting interface 1

FIRST → Plot the DATA Clapeyron Relation

Start Basic Fitting Interface 1

Start basic fitting interface 2
Start Basic Fitting Interface 2 Clapeyron Relation

Goodness of Fit; smaller is Better

Expand Dialog Box

Start basic fitting interface 3

Result Clapeyron Relation

Chk by polyfit

Start Basic Fitting Interface 3

>> p = polyfit(Theta,Omega,1)

p =

0.8737 0.0429

Caveat Clapeyron Relation

Greek letters in plots
Greek Letters in Plots Clapeyron Relation

Plot discoverables
Plot “Discoverables” Clapeyron Relation

% "Discoverable" Functions Displayed Clapeyron Relation

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



% PLot Side-by-Side


plot(x,ye), grid


plot(x,ypp), grid


plot(x,ypm), grid