Bruce Mayer, PE Licensed Electrical & Mechanical Engineer [email protected]
Bruce Mayer, PE Registered Electrical & Mechanical Engineer [email protected]
description
Transcript of Bruce Mayer, PE Registered Electrical & Mechanical Engineer [email protected]
[email protected] • ENGR-25_Plot_Model-4.ppt1
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Bruce Mayer, PERegistered Electrical & Mechanical Engineer
Engr/Math/Physics 25
Chp6 MATLAB
Fcn Discovery
[email protected] • ENGR-25_Plot_Model-4.ppt2
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 “nth” Degree Polynomials
Use MATLAB’s “Basic Fitting” Utility to find Math models for Plotted Data
[email protected] • ENGR-25_Plot_Model-4.ppt3
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 (r2)
• Scale Data if Needed– Creates more meaningful spacing
[email protected] • ENGR-25_Plot_Model-4.ppt4
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
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
[email protected] • ENGR-25_Plot_Model-4.ppt5
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 Functions1. 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 = bxm – gives a straight line when plotted on log-log
axes
3. The exponential function y = b·10mx or y = b·emx – Yields a straight line when plotted on a
semilog plot with logarithmic y-axis
[email protected] • ENGR-25_Plot_Model-4.ppt6
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
bmxy
b
y
xx
yxym
Transform the Power Function to Line-Like Form
mbxyPwrFcn Take ln of both sides
bxmyxbbxy mm
lnlnlnlnlnlnln
pY pX pB
[email protected] • ENGR-25_Plot_Model-4.ppt7
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
xy ln vs.ln
Example:
ppp
mm
BmXYbxmyxbbxy
lnlnlnlnln
If The Data Follows the Power Function Then a Plot of
91713 73.1
xxy
[email protected] • ENGR-25_Plot_Model-4.ppt8
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Power Function y = 13x1.73
Rectlinear Plot Log-Log Plot
0 10 20 30 40 50 60 70 80 90 1000
0.5
1
1.5
2
2.5
3
3.5x 10
4
x
y
Power Function
1.5 2 2.5 3 3.5 4 4.5 55.5
6
6.5
7
7.5
8
8.5
9
9.5
10
10.5
ln(x)
ln(y
)
Power Function
[email protected] • ENGR-25_Plot_Model-4.ppt9
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
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
100
101
102
102
103
104
105
y = 13x1.73
x
y
[email protected] • ENGR-25_Plot_Model-4.ppt10
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
mxbey Again taking the ln
bmxyemxb
bey mx
lnlnlnln
lnln
e
e
BbYy
lnln
ee BmxY A SemiLog (log-y)
plot Should Show as a Straight Line
[email protected] • ENGR-25_Plot_Model-4.ppt11
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Exponential Fcn Plot Plot 115ln61.0ln115 61.0 tvev t
0 1 2 3 4 5 6 7 8 9 100
20
40
60
80
100
120
t
v
Exponential Function
0 1 2 3 4 5 6 7 8 9 10-2
-1
0
1
2
3
4
5
t
ln(v
)
Exponential Function
ln(115) = 4.79
Rectlinear Plot SemiLog Plot
[email protected] • ENGR-25_Plot_Model-4.ppt12
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
V = 115e-0.61t by MATLAB semilogy
0 1 2 3 4 5 6 7 8 9 1010
-1
100
101
102
103
v = 115e-0.61t
t
v
>> 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
[email protected] • ENGR-25_Plot_Model-4.ppt13
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Steps for Function Discovery1. 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
[email protected] • ENGR-25_Plot_Model-4.ppt14
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
“Discoverable” Functions
-5 0 50
50
100
150
x
ye
-5 0 50
5
10
15
20
25
x
ypp
-5 0 50
50
100
150
200
250
300
350
400
x
ypm
xe ey 2xypp
2xy pm
In most applications x is NONnegative
[email protected] • ENGR-25_Plot_Model-4.ppt15
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Steps for Function Discovery2. 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, thena. If y(0) = 0, then try the power
function.b. If y(0) 0, then try the exponential
functionc. If data is not given for x = 0,
then proceed to step 3.
mx
m
bey
bxy
bmxy
[email protected] • ENGR-25_Plot_Model-4.ppt16
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Steps for Function Discovery3. 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.
mx
m
bey
bxy
bmxy
[email protected] • ENGR-25_Plot_Model-4.ppt17
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SemiLog and LogLog Scales
-5 0 510
-3
10-2
10-1
100
101
102
103
x
ye
10-2
100
102
10-3
10-2
10-1
100
101
102
10-2
100
102
10-2
10-1
100
101
102
103
x
ypm
• Note Change in power Function x-axis scales– In this case x MUST be POSITIVE
xe ey 2xypp
2xy pm
[email protected] • ENGR-25_Plot_Model-4.ppt18
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Steps for Function Discovery5. 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
mx
m
bey
bxy
bmxy
[email protected] • ENGR-25_Plot_Model-4.ppt19
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 =p1z +p2 then polyfit on data Vectors
W & Z returns: p = ployfit(Z,W,1) = [p1, p2] → [m, b]
[email protected] • ENGR-25_Plot_Model-4.ppt20
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• p1 → m (slope)• p2 → b (intercept)
Thus polyfit can provide m & b for any of the previously noted functions AFTER the appropriate Linearization Transform
[email protected] • ENGR-25_Plot_Model-4.ppt21
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, C2H5OH, 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
Pv for Ethanol (Torr)
Temperature(Kelvins)
760 351.4400 336.5200 321.4100 307.960 29940 29220 28110 270.75 2611 241.7
[email protected] • ENGR-25_Plot_Model-4.ppt22
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 Pv ~ em/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
240 260 280 300 320 340 3600
100
200
300
400
500
600
700
800
T (K)
Pv
(Tor
r)
Ethanol Vapor Pressure
[email protected] • ENGR-25_Plot_Model-4.ppt23
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Compare LogLog vs SemiLogY Log Log Plot
100.5
100.6
100
101
102
103
Ethanol Vapor Pressure
1000/T (1/K)
Pv
(Tor
r)
logY vs linX
2.8 3 3.2 3.4 3.6 3.8 4 4.210
0
101
102
103
Ethanol Vapor Pressure
1000/T (1/K)
Pv
(Tor
r)
Looks like an Exponential in 1/T • e.g., the Clapeyron eqn
[email protected] • ENGR-25_Plot_Model-4.ppt24
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 1st-Cut Assume the Clapeyron
form
Tmv
TmBBTmv
v
beP
eeeP
BT
mP
1
11
or1ln
Now Xform
BTmPv 1ln
x eBeY Thus Plot
ln(Pv) vs 1/T
[email protected] • ENGR-25_Plot_Model-4.ppt25
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
2.8 3 3.2 3.4 3.6 3.8 4 4.2
x 10-3
0
1
2
3
4
5
6
7
1/T (1/K)ln
(Pv)
(ln(
Torr)
)
Ethanol Vapor Pressure - Clapeyron Plot
[email protected] • ENGR-25_Plot_Model-4.ppt26
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
TP
mxBY
v
ee
14.51303.21ln
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
TPv 10001304.52512.21ln
[email protected] • ENGR-25_Plot_Model-4.ppt27
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
m & b by polyfit(x,y,1)cont
2.8 3 3.2 3.4 3.6 3.8 4 4.20
1
2
3
4
5
6
7
1000/T (1000/K)
ln(P
v) (l
n(To
rr))
Ethanol Vapor Pressure - Clapeyron Plot
ln(Pv) =21.2512-5130.4(1/T)
Tv eP 14.51302512.21
[email protected] • ENGR-25_Plot_Model-4.ppt28
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
All Done for Today
PowerandExps
[email protected] • ENGR-25_Plot_Model-4.ppt29
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Bruce Mayer, PELicensed Electrical & Mechanical Engineer
Engr/Math/Physics 25
Appendix 6972 23 xxxxf
[email protected] • ENGR-25_Plot_Model-4.ppt30
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')
91713 73.1
xxy
[email protected] • ENGR-25_Plot_Model-4.ppt31
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')
115ln61.0ln115 61.0 tvev t
[email protected] • ENGR-25_Plot_Model-4.ppt32
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Altitude of Right Triangle The Area of RIGHT
Triangle
y
x
L
h
yxA 21 The Area of an ARBITRARY
Triangle
hLA 21 By Pythagoras for
Rt-Triangle
22 yxL
[email protected] • ENGR-25_Plot_Model-4.ppt33
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Altitude of Right Triangle cont
y
x
L h
hyxyx 222121
Solving for h
22 yx
yxh
Lx 21 Base&Base Equating the A=½·Base·Hgt noting that
[email protected] • ENGR-25_Plot_Model-4.ppt34
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
[email protected] • ENGR-25_Plot_Model-4.ppt35
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Start Basic Fitting Interface 1 FIRST →
Plot the DATA
[email protected] • ENGR-25_Plot_Model-4.ppt36
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Start Basic Fitting Interface 2
Expand Dialog Box
Goodness of Fit; smaller is
Better
[email protected] • ENGR-25_Plot_Model-4.ppt37
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Start Basic Fitting Interface 3 Result Chk by
polyfit
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Theta
Om
ega
Frog Croaking in the Evening - 2045hrs
y = 0.8737*x + 0.04286
Croak Data linear Fit
>> p = polyfit(Theta,Omega,1)p = 0.8737 0.0429
[email protected] • ENGR-25_Plot_Model-4.ppt38
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Caveat
[email protected] • ENGR-25_Plot_Model-4.ppt39
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Greek Letters in Plots
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1Frog Croaking Frequency
Croak Data Linear Fit
= 0.8737 + 0.04286
[email protected] • ENGR-25_Plot_Model-4.ppt40
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Plot “Discoverables”% "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 grapheplot(x,ye, x,ypp, x,ypm),grid,legend('ye', 'ypp', 'ypm')disp('Showing MultiGraph Plot - Hit ANY KEY to continue')pause%% PLot Side-by-Sidesubplot(1,3,1)plot(x,ye), gridsubplot(1,3,2)plot(x,ypp), gridsubplot(1,3,3)plot(x,ypm), grid
[email protected] • ENGR-25_Plot_Model-4.ppt41
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 grapheplot(x,ye, x,ypp, x,ypm),grid,legend('ye', 'ypp', 'ypm')disp('Showing MultiGraph Plot - Hit ANY KEY to continue')pause%% PLot Side-by-Sidesubplot(1,3,1)plot(x,ye), gridsubplot(1,3,2)plot(x,ypp), gridsubplot(1,3,3)plot(x,ypm), grid