Bruce Mayer, PE Registered Electrical & Mechanical Engineer BMayer@ChabotCollege
Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege
-
Upload
reuben-simmons -
Category
Documents
-
view
11 -
download
0
description
Transcript of Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege
[email protected] • ENGR-25_Plot_Mode_1.ppt1
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Bruce Mayer, PELicensed Electrical & Mechanical Engineer
Engr/Math/Physics 25
Chp5 MATLABPlots &
Models 1
[email protected] • ENGR-25_Plot_Mode_1.ppt2
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Learning Goals List the Elements of a COMPLETE Plot
• e.g.; axis labels, legend, units, etc.
Construct Complete Cartesian (XY) plots using MATLAB• Modify or Specify MATLAB Plot Elements:
Line Types, Data Markers, Tic Marks
Distinguish between INTERPolation and EXTRAPolation
[email protected] • ENGR-25_Plot_Mode_1.ppt3
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Learning Goals cont
Construct using MATLAB SemiLog and LogLog Cartesian Plots
Use MATLAB’s InterActive Plotting Utility to Fine-Tune Plot Appearance
Create “Linear-Transform” Math Models for measured Physical Data• Linear Function → No Xform• Power Function → LogLog Xform• Exponential Function → SemiLog Xform
[email protected] • ENGR-25_Plot_Mode_1.ppt4
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Learning Goals cont
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_Mode_1.ppt5
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_Mode_1.ppt6
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Why Plot?
Engineering, Math, and Science are QUANTITATIVE Endeavors, we want NUMBERS as Well as Words
Many times we Need to• Understand The (functional) relationship
between two or More Variables• Compare the Values of MANY Data Points
[email protected] • ENGR-25_Plot_Mode_1.ppt7
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Why Plot? cont
Plots have TREMENDOUS Utility in Two Major Areas
1. Communication• To Help OTHERS understand the
RESULTS of Your Tests or Experiments or Theories
2. Analysis• To Help You ANALYZE Data or
Theories to Determine the Significance or Meaning of the Data
[email protected] • ENGR-25_Plot_Mode_1.ppt8
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Plotting Trivia
Rene Decartes (1596-1650) Developed “Cartesian” (XY) Plots in about 1637
Florence Nightingale Developed the “Polar Area Plot” (Pie Chart) in 1857
[email protected] • ENGR-25_Plot_Mode_1.ppt9
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Sys3 2X200 MultiBlok, 997671 250-13.8 PreWeld Pi Tube-1
0
25
50
75
100
125
150
175
200
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
Hole Number (1 = closest to Manifold Block)
Ind
ivid
ual
Ho
le
P (
10X
To
rr)
DNS Tube-1 BMayer Tube1
DNS Normalized BMayer Normalized
PARAMETERS• For Single Tube Manifold• Flow = ??/0.24 slpm/hole• Exh to Atm Pressure (~750Torr)• Test Engr = DNStoddard, BMayer• Test Date = 09Mar00/10Mar
file = HbH997671PreW09Mar00.xls
Plot Title
Axis Title
Tic Mark
Tic Mark Label
Lege
nd
Data Symbol
Annot
atio
ns
Axis UNITS Connecting Line
[email protected] • ENGR-25_Plot_Mode_1.ppt10
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Gate Voltate to Balance ElectroStatic and Spring Forces vs. d
0
2
4
6
8
10
12
14
16
18
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0
Cantilever Height, d (µm)
Gat
e P
ote
nti
al
(Vd
c)
file = ElectroStatics_0104.xls
Threshold
Turn-On(Zip-Up)
Turn-Off(Peel-Off)
PARAMETERS• E = 135 Gpa (PolySi)• L = 100 µm• W = 60 µm• t = 3 µm• do = 2 µm• Z = 300 µm • VTh = 17.00396 Vdc• Vr = 7.903 Vdc
Vr Arrow CallOut
Theoretical Plot → NO Data Markers
Important Output Value
[email protected] • ENGR-25_Plot_Mode_1.ppt11
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
MATLAB Plot Example
Consider a Rocket Launch
A Math Model for the Height, y, vs. the Distance, x:
xy 73.143.0• Where both x & y
are in units of miles
Use MATLAB to Plot y vs x for a 51 mi DownRange Dist
[email protected] • ENGR-25_Plot_Mode_1.ppt12
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
The Results
0 10 20 30 40 50 600
0.5
1
1.5
2
2.5
3
3.5
4
4.5
Distance (mi)
Hei
ght (
mi)
Rocket Height as a Function of Downrange Distance
>> x = [0:0.1:51];>> y = 0.43*sqrt(1.73*x);>> plot(x,y)>> xlabel('Distance (mi)')>> ylabel('Height (mi)')>> title('Rocket Height as a Function of Downrange Distance')
The Command Session
[email protected] • ENGR-25_Plot_Mode_1.ppt13
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Plot OutPut
The plot appears in the Figure window Output from One of
1. Use the menu system. Select Print on the File menu in the Figure window. Answer OK when you are prompted to continue the printing process.
2. Type print at the command line. This command sends the current plot directly to the printer.
3. Save the plot to a file to be printed later or imported into another application such as PowerPoint. You need to know something about graphics file formats to use this file properly. See the subsection Exporting Figures.
[email protected] • ENGR-25_Plot_Mode_1.ppt14
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Elements of a Useful Plot
The essential features of a Maximally Understandable Plot1. Each axis must be labeled with the name
of the quantity being plotted and its units. – If two or more quantities having different
units are plotted (such as when plotting both speed and distance versus time), then indicate the units in the axis label if there is room, or in the legend or labels for each curve
2. Each axis should have regularly spaced tick marks at convenient intervals - not too sparse, but not too dense - with a spacing that is easy to interpret and interpolate. – e.g.; use 0.1, 0.2, and so on, rather than 0.13,
0.26
[email protected] • ENGR-25_Plot_Mode_1.ppt15
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Elements of a Useful Plot cont
3. If you plot more than one curve or data set, label each Curve/DataSet on its plot or use a legend to distinguish them.
4. If you are preparing multiple plots of a similar type or if the axes’ labels cannot convey enough information, use a title. When in Doubt, TITLE
5. If you plot measured data, plot each data point with a symbol such as a circle, square, or cross – use the same symbol for every point in the
same data set. – If there are many data points (within a single
Data-Set), then plot them using the dot symbol.
[email protected] • ENGR-25_Plot_Mode_1.ppt16
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Elements of a Useful Plot cont
6. Sometimes data symbols are connected by lines to help the viewer visualize the data, especially if there are few data points. However, connecting the data points, especially
with a solid line, might be interpreted to imply knowledge of what occurs between the data points. Take appropriate care to prevent such MisInterpretation.
7. If you are plotting points generated by evaluating a function (as opposed to measured data), do not use a symbol to plot the points. Instead, be sure to generate many points, and connect the points with solid lines. The Curve should be SMOOTH
[email protected] • ENGR-25_Plot_Mode_1.ppt17
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
grid Command
The grid command displays gridlines at the tick marks corresponding to the tick labels. • Type grid on to add gridlines; • Type grid off to stop plotting gridlines. • When used by itself, grid toggles this
feature on or off, but you might want to use grid on and grid off to be sure.
[email protected] • ENGR-25_Plot_Mode_1.ppt18
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
axis Command The axis command overrides the
MATLAB Default selections for the axis limits.
The basic syntax: axis([xmin xmax ymin ymax]).
This command sets the scaling for the x- and y-axes to the minimum and maximum values indicated. Note that, unlike an array, this command does not use commas to separate the values.
[email protected] • ENGR-25_Plot_Mode_1.ppt19
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
LineWidth Command
MATLAB’s Default width and color for a plotted line are• Thin• Blue
This “thin blue line” is often hard to SEE and to PHOTOCOPY
Use 'LineWidth',n, to increase WIDTH
Use color-spec to make BLACK
[email protected] • ENGR-25_Plot_Mode_1.ppt20
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Affect of grid, axis, LineWidth
0 5 10 15 20 25 30 35 40 45 500
0.5
1
1.5
2
2.5
3
3.5
4
Distance (mi)
Hei
ght
(mi)
Rocket Height as a Function of Downrange Distance
plot(x,y, 'k', 'LineWidth', 3), xlabel('Distance (mi)'),... ylabel('Height (mi)'),grid on, axis([0 51 0 4.1]),... title('Rocket Height as a Function of Downrange Distance')
Command Session
Compare to the Previous Version
[email protected] • ENGR-25_Plot_Mode_1.ppt21
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Plotting Vectors A single Row or
Column Vector, v, can be plotted as plot(v)• The X-Axis value
= Vector Index; 1, 2, 3,...n
• The Y-Axis value = Vector-Value
Example: Plot TOP DataSet from sld-9 using Row Vector
The 39 Data Points for Vector, p
The Plot Statement
>> p = [143, 151, 164, 149, 154, 169, 164, 172, 181, 183, 167, 177, 163, 199, 164, 168, 162, 155, 191, 153, 151, 150, 143, 177, 142, 145, 138, 136, 147, 143, 161, 137, 138, 138, 136, 140, 147, 148, 151]
>> plot(p), xlabel('Hole No'), ylabel('DelP (10x Torr)'),...title('Distribution Tube Uniformity Test'), grid
[email protected] • ENGR-25_Plot_Mode_1.ppt22
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Vector Plot
0 5 10 15 20 25 30 35 40130
140
150
160
170
180
190
200
Hole No
Del
P (
10x
Tor
r)
Distribution Tube Uniformity Test
Sys3 2X200 MultiBlok, 997671 250-13.8 PreWeld Pi Tube-1
0
25
50
75
100
125
150
175
200
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
Hole Number (1 = closest to Manifold Block)
Ind
ivid
ua
l H
ole
P
(1
0X
To
rr)
DNS Tube-1 BMayer Tube1
DNS Normalized BMayer Normalized
PARAMETERS• For Single Tube Manifold• Flow = ??/0.24 slpm/hole• Exh to Atm Pressure (~750Torr)• Test Engr = DNStoddard, BMayer• Test Date = 09Mar00/10Mar
file = HbH997671PreW09Mar00.xls
[email protected] • ENGR-25_Plot_Mode_1.ppt23
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Complex Number Plots
MATLAB can Not Plot x vs z if z is Complex
For Complex z, the statement plot(z) is effectively the Same as plot(real(z), imag(z))
Example Plot for
Command Session
100for
7.03.0cos
n
jz n
>> w = 0.3-.7j>> n = [0:0.1:10];>> z = cos(w.^n);>> plot(z), xlabel('Re'), ylabel('Im')>> u = cos(w^4.7)u = 1.0011 - 0.0386i>> u = cos(w^.6)u = 0.9182 + 0.3476i
[email protected] • ENGR-25_Plot_Mode_1.ppt24
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Complex Plot
0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
Re
Im
100for
7.03.0cos
n
jz n
[email protected] • ENGR-25_Plot_Mode_1.ppt25
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
fplot → “Smart” Plotting
To make a quick Function-Plot, use MATLAB’s fplot
Need Only• The FUNCTION• Independent
Variable RANGE
The fplot Syntax:fplot(‘string’, [xmin, xmax])
• Where
– String Text String that describes the function
– xmin & xmax are the plotting Range:
Example the transient Response for an RLC Circuit (c.f. ENGR43):
ttetu t 13sin1113cos73.0
• Apply fplot over the range of 0-9 sec
[email protected] • ENGR-25_Plot_Mode_1.ppt26
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
The fplot
0 1 2 3 4 5 6 7 8 9-15
-10
-5
0
5
10
15
ttetu t 13sin1113cos73.0
fplot('(exp(-0.3*t))*(7*cos(13*t) - 11*sin(13*t))', [0 9])
Command Session
>> u = '(exp(-0.3*t))*(7*cos(13*t) - 11*sin(13*t))';>> fplot(u, [0 9])
EQUIVALENT Session
[email protected] • ENGR-25_Plot_Mode_1.ppt27
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Anonymous Function & fplot
0 5 10 15 20 25 30 35-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
uofx = @(x) cos(x)/log(x+3)
fplot(uofx, [0 37]),grid
Command Session
[email protected] • ENGR-25_Plot_Mode_1.ppt28
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Beware fplot Syntax
0 1 2 3 4 5 6 7 8 9-15
-10
-5
0
5
10
15
uoft = @(t) (exp(-0.3*t)).*(7*cos(13*t) - 11*sin(13*t))
fplot('uoft', [0 9]),grid
0 1 2 3 4 5 6 7 8 90
1
2
3
4
5
6
7
8
9
fplot(uoft, [0 9]),grid
[email protected] • ENGR-25_Plot_Mode_1.ppt29
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Plot Polynomials w/ polyval
Recall the Polynomial fcn; e.g.
• Where– p is a Vector
containing of the (constant) coefficients of the polynomial
y = polyval(p,x)
Find y using MATLAB’s polyval function
1953117 23 xxxy
– x is the Value of the independent variable
Evaluate the example polynomial at x = 73
>> P = [17 -31 5 19];>> Y_73 = polyval(P,73)Y_73 = 6448474
[email protected] • ENGR-25_Plot_Mode_1.ppt30
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Plotting w/ polyval
Let’s Plot this Polynomial over −1.8 x 4.2
Note the Zero Coeff. For the 3rd Degree Term
94.111.673.4031.2 2345 xxxxxy
>> p5 = [1,-2.31,0,-4.73,6.11,1.94];>> x = [-1.8:.01:4.2];>> plot(x, polyval(p5,x)), xlabel('x'), ylabel('y = f(x)')
The Command Window Session
[email protected] • ENGR-25_Plot_Mode_1.ppt31
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
The polyval Plot (also fminbnd)
94.111.673.4031.2 2345 xxxxxyThe
FigureWindow
>> pofx = @(x) x.^5 - 2.31*x.^4 - 4.73*x.^2 + 6.11*x + 1.94pofx = @(x)x.^5-2.31*x.^4-4.73*x.^2+6.11*x+1.94
>> [xmin, minval] = fminbnd(pofx, 0,3)
xmin = 2.1371e+000
minval = -1.0212e+001
[email protected] • ENGR-25_Plot_Mode_1.ppt32
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Find Local Minimum
Find The MIN between 1-3 using polyval and min commands
-2 -1 0 1 2 3 4 5-100
0
100
200
300
400
500
600
x
y
>> x1 = [1:.001:3];>> y1 = polyval(p5,x1);>> [yMin, kMin] = min(y1)
yMin = -10.2117
kMin = 1138
>> xMin = x1(kMin)
xMin = 2.1370
94.111.673.4031.2 2345 xxxxxy
2117.10,1370.2
[email protected] • ENGR-25_Plot_Mode_1.ppt33
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Saving Figures
To save a figure that can be opened in subsequent MATLAB sessions, save it in a figure file with the .fig file name extension
To do this, select Save from the Figure window File menu or click the Save button (the disk icon) on the toolbar.
If this is the first time you are saving the file, the Save As dialog box appears. Make sure that the type is MATLAB Figure (*.fig). Specify the name you want assigned to the figure file. Click OK.
[email protected] • ENGR-25_Plot_Mode_1.ppt34
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Why .fig File?
The MATLAB FIG-file is a binary format to which you can save figures so that they can be opened in subsequent MATLAB sessions.
What is Saved whole figure, including • Graph(s), • Graph data• Annotations
Edit later withOUT ReDoing DATA
[email protected] • ENGR-25_Plot_Mode_1.ppt35
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Saving to .fig – Step-1
1. In Figure 1 Window Click File→Save As...
[email protected] • ENGR-25_Plot_Mode_1.ppt36
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Saving to .fig – Step-2
2. To Open Using MATLAB Select the .fig file-format
3. Type in a descriptive FileName and hit Save
[email protected] • ENGR-25_Plot_Mode_1.ppt37
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Exporting Figures
To save the figure in a format that can be used by another application, such as the standard graphics file formats; e.g., TIFF or JPG, perform these steps1. Select Export Setup from the File menu.
This dialog lets you specify options for the output file, such as the figure size, fonts, line size and style, and output format
2. Select Export from the Export Setup dialog. A standard Save As dialog appears.
[email protected] • ENGR-25_Plot_Mode_1.ppt38
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Exporting Figures cont
3. Select the format from the list of formats in the Save As type menu. – This selects the format of the exported file and
adds the standard file name extension given to files of that type The Instructor likes the .jpg (Joint Picture experts
Group) format; a good compromise of: compatibility, file-size, and resolution
4. Enter the name you want to give the file, less the extension. Then click Save.
[email protected] • ENGR-25_Plot_Mode_1.ppt39
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Exporting to file Step-1
1. In Figure 1 Window Click File→Export Setup...
[email protected] • ENGR-25_Plot_Mode_1.ppt40
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Saving to file Step-2
2. In the Export Setup Dialog Box Click Export
3. In the Save As Dialog Box Type in a descriptive FileName and hit Save
[email protected] • ENGR-25_Plot_Mode_1.ppt41
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
The .jpg export
[email protected] • ENGR-25_Plot_Mode_1.ppt42
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Windows ClipBoard Copy
MATLAB provides a Very Nice Utility in which a Plot is sent to the MSWindows ClipBoard for Subsequent Pasting into Other Applications
To Save to the ClipBoard1. Select Copy Options from the Edit menu.
The Copying Options page of the Preferences dialog box appears.
2. Complete the fields on the Copying Options page and click OK.
3. Select Copy Figure from the Edit menu.
[email protected] • ENGR-25_Plot_Mode_1.ppt43
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Copy to Clipboard Step-1
1. In Figure 1 Window Click Edit→Copy Options...
[email protected] • ENGR-25_Plot_Mode_1.ppt44
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Copy to Clipboard Steps 2&3
2. In the Preferences Dialog Box check the Copy-Options Boxes as you see Fit
3. Close the Dialog Box
[email protected] • ENGR-25_Plot_Mode_1.ppt45
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Copy to Clipboard – Steps 4&5
4. In the Figure Window use File → Copy Figure to send the plot to the clipboard
5. Paste the plot image into PowerPoint, Word, etc.
[email protected] • ENGR-25_Plot_Mode_1.ppt46
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
The Copy Figure export
-2 -1 0 1 2 3 4 5-100
0
100
200
300
400
500
600
x
y =
f(x
)
[email protected] • ENGR-25_Plot_Mode_1.ppt47
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
All Done for Today
The Best Plot EVERDone
The French engineer, Charles Minard (1781-1870), illustrated the disastrous result of Napoleon's failed Russian campaign of 1812. The graph shows the size of the army by the width of the band across the map of the campaign on its outward and return legs, with temperature on the retreat shown on the line graph at the bottom. Many consider Minard's original the BEST statistical graphic ever drawn.
[email protected] • ENGR-25_Plot_Mode_1.ppt48
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Bruce Mayer, PELicensed Electrical & Mechanical Engineer
Engr/Math/Physics 25
Appendix 6972 23 xxxxf