Bruce Mayer, PE
Licensed Electrical & Mechanical Engineer
BMayer@ChabotCollege.edu
Engineering/Math/Physics 25: Computational Methods
1
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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
Engineering/Math/Physics 25: Computational Methods
2
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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
Engineering/Math/Physics 25: Computational Methods
3
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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 (r 2 )
• Scale Data if Needed
– Creates more meaningful spacing
Engineering/Math/Physics 25: Computational Methods
4
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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
Engineering/Math/Physics 25: Computational Methods
5
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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
Engineering/Math/Physics 25: Computational Methods
6
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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
7
Significance or Meaning of the Data
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
Rene Decartes (1596-1650)
Developed “Cartesian” (XY)
Plots in about 1637
Florence Nightingale Developed the
“Polar Area Plot” (Pie Chart) in 1857
Engineering/Math/Physics 25: Computational Methods
8
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
Sys3 2X200 MultiBlok, 997671 250-13.8 PreWeld
P i
Tube-1
200
175
150
Tic Mark Label
125 Axis UNITS
Connecting Line
Data Symbol
100
Tic Mark
75
50
25
0
1
PARAMETERS
• For Single Tube Manifold
• Flow = ??/0.24 slpm/hole
• Exh to Atm Pressure (~750Torr)
• Test Engr = DNStoddard, BMayer
• Test Date = 09Mar00/10Mar
3 5 7
DNS Tube-1
DNS Normalized
BMayer Tube1
BMayer Normalized
9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
Hole Number (1 = closest to Manifold Block) file = HbH997671PreW09Mar00.xls
Engineering/Math/Physics 25: Computational Methods
9
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
Gate Voltate to Balance ElectroStatic and Spring Forces vs. d
18
16
14
12
PARAMETERS
• E = 135 Gpa (PolySi)
• L = 100 µm
• W = 60 µm
• t = 3 µm
• d o
= 2 µm
• Z = 300 µm
• V
Th
= 17.00396 Vdc
• V r
= 7.903 Vdc
Threshold
10
Turn-Off
(Peel-Off)
Turn-On
(Zip-Up)
8
V r
6
4
Arrow CallOut
Theoretical Plot → NO Data Markers
2
Important Output Value
0
0.0
0.2
file = ElectroStatics_0104.xls
0.4
0.6
Cantilever Height, d (µm)
Engineering/Math/Physics 25: Computational Methods
10
0.8
1.0
1.2
1.4
1.6
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
1.8
2.0
Consider a Rocket
Launch
A Math Model for the Height, y, vs. the Distance, x: y
0 .
43 1 .
73 x
• Where both x & y are in units of miles
Use MATLAB to Plot y vs x for a 51 mi
DownRange Dist
Engineering/Math/Physics 25: Computational Methods
11
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
Rocket Height as a Function of Downrange Distance
4.5
4
3.5
3
2.5
2
1.5
>> x = [0:0.1:51];
>> y = 0.43*sqrt(1.73*x);
>> plot(x,y)
>> xlabel('Distance (mi)')
>> ylabel('Height (mi)')
1
0.5
0
0 10 20 30
Distance (mi)
Engineering/Math/Physics 25: Computational Methods
12
The Command Session
>> title('Rocket Height as a
Function of Downrange Distance')
40 50 60
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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 .
Engineering/Math/Physics 25: Computational Methods
13
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
The essential features of a Maximally
Understandable Plot
1. 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
Engineering/Math/Physics 25: Computational Methods
14
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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.
Engineering/Math/Physics 25: Computational Methods
15
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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
Engineering/Math/Physics 25: Computational Methods
16
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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.
Engineering/Math/Physics 25: Computational Methods
17
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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
18 use commas to separate the values.
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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
Engineering/Math/Physics 25: Computational Methods
19
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
4
Rocket Height as a Function of Downrange Distance
3.5
3
2.5
Compare to the
2
1.5
1
0.5
0
0 5
Command Session 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')
10 15 20 25 30
Distance (mi)
Engineering/Math/Physics 25: Computational Methods
35 40 45 50
Previous
Version
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
20
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 =
VectorValue
Example: Plot TOP
DataSet from sld-9 using Row Vector
Engineering/Math/Physics 25: Computational Methods
21
The 39 Data Points for Vector, p
>> 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]
The Plot Statement
>> plot( p ), xlabel('Hole
No'), ylabel('DelP (10x
Torr)'),...
title('Distribution Tube
Uniformity Test'), grid
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
Distribution Tube Uniformity Test
200
190
180
170
160
150
140
130
0 5 10 15 20
Hole No
Engineering/Math/Physics 25: Computational Methods
22
25
Sys3 2X200 MultiBlok, 997671 250-13.8 PreWeld
P i
Tube-1
200
175
150
125
100
75
50
25
0
1
PARAMETERS
• For Single Tube Manifold
• Flow = ??/0.24 slpm/hole
• Exh to Atm Pressure (~750Torr)
• Test Engr = DNStoddard, BMayer
• Test Date = 09Mar00/10Mar
3 5 7 9
DNS Tube-1
DNS Normalized
BMayer Tube1
BMayer Normalized
11 13 15 17 19 21 23 25 27 29
Hole Number (1 = closest to Manifold Block)
31 33 35 37 39 file = HbH997671PreW09Mar00.xls
30 35 40
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
MATLAB can Not
Plot x vs z if z
cos
z is Complex
For Complex z, the statement plot(z)
0 .
3
0 .
7 for n
0
10
Command Session
>> w = 0.3-.7j
j
>> n = [0:0.1:10];
>> z = cos(w.^n);
n is effectively the
>> plot(z), xlabel('Re'),
Same as
ylabel('Im') plot(real(z), >> u = cos(w^4.7) u = imag(z))
1.0011 - 0.0386i
Example Plot for
>> u = cos(w^.6) u =
0.9182 + 0.3476i
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
Engineering/Math/Physics 25: Computational Methods
23
0.5
0.4
0.3
0.2
0.1
0
-0.1
-0.2
0.5
0.6
0.7
0.8
0.9
Engineering/Math/Physics 25: Computational Methods
Re
24 z
cos
0 .
3 for n
0
1 1.1
1.2
1.3
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
10
0 .
7 j
n
To make a quick
Function-Plot, use
MATLAB’s fplot
– String
Text String that describes the function
– xmin & xmax are the plotting Range:
Need Only
• The FUNCTION
• Independent
Variable RANGE
The fplot Syntax: fplot(‘string’, [xmin, xmax])
• Where u
Example the transient Response for an RLC Circuit
(c.f. ENGR43):
e
0 .
3 t
7 cos
11 sin
• Apply fplot over the range of 0-9 sec
Engineering/Math/Physics 25: Computational Methods
25
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
15
10 u
e
0 .
3 t
7 cos
11 sin
Command Session fplot ('(exp(-0.3*t))*(7*cos(13*t)
- 11*sin(13*t))', [0 9])
5
0
-5
-10
EQUIVALENT Session
>> u = '(exp(-0.3*t))*(7*cos(13*t)
- 11*sin(13*t))';
>> fplot(u, [0 9])
-15
0 1 2 3
Engineering/Math/Physics 25: Computational Methods
26
4 5 6 7 8 9
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
1
0.8
Command Session uofx = @(x) cos(x)/log(x+3)
0.6
fplot(uofx, [0 37]),grid
0.4
0.2
0
-0.2
-0.4
-0.6
0 5 10 15
Engineering/Math/Physics 25: Computational Methods
27
20 25 30
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
35
uoft = @(t) (exp(-0.3*t)).*(7*cos(13*t) -
11*sin(13*t))
15
7
6
5
4
9
8
10
5
0
3
-5
2
-10
1
0
0 1 2 3 4 5 6 7 8 fplot(' uoft ', [0 9]), grid
Engineering/Math/Physics 25: Computational Methods
28
9
-15
0 1 2 3 4 5 6 7 fplot(uoft, [0 9]), grid
8
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
9
Recall the y
Polynomial fcn; e.g.
17 x
3
31 x
2
5 x
19
Find y using
MATLAB’s polyval function y = polyval(p,x)
29
• Where
– p is a Vector containing of the
(constant) coefficients of the polynomial
Engineering/Math/Physics 25: Computational Methods
– 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
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
y
Let’s Plot this Polynomial over −1.8 x
4.2
x
5
2 .
31 x
4
0 x
3
4 .
73 x
2
6 .
11 x
1 .
94
Note the Zero Coeff.
For the 3 rd Degree
Term
The Command
Window Session
>> 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)')
Engineering/Math/Physics 25: Computational Methods
30
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
The
Figure
Window y
x
5
2 .
31 x
4
0 x
3
4 .
73 x
2
6 .
11 x
1 .
94
>> pofx = @(x) x.^5 - 2.31*x.^4 - 4.73*x.^2 + 6.11*x + 1.94
pofx =
@(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
Engineering/Math/Physics 25: Computational Methods
31
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
600
500
400
Find The MIN between 1-3 using polyval and min commands y
x
5
2 .
31 x
4
0 x
3
4 .
73 x
2
6 .
11 x
1 .
94
>> x1 = [1:.001:3];
>> y1 = polyval(p5,x1);
>> [yMin, kMin] = min(y1)
300 yMin =
-10.2117
200 kMin =
1138
100
0
2 .
1370 ,
10 .
2117
-100
-2 -1 0 1 2 x
Engineering/Math/Physics 25: Computational Methods
3
32
4
>> xMin = x1(kMin)
5 xMin =
2.1370
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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.
Engineering/Math/Physics 25: Computational Methods
33
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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
Engineering/Math/Physics 25: Computational Methods
34
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
1. In Figure 1
Window
Click File
→
Save As...
Engineering/Math/Physics 25: Computational Methods
35
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
2. To Open
Using
MATLAB
Select the
.fig fileformat
3. Type in a descriptive
FileName and hit
Save
Engineering/Math/Physics 25: Computational Methods
36
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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 steps
1. 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.
Engineering/Math/Physics 25: Computational Methods
37
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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 .
Engineering/Math/Physics 25: Computational Methods
38
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
1. In Figure 1
Window Click
File
→
Export
Setup...
Engineering/Math/Physics 25: Computational Methods
39
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
2. In the Export
Setup Dialog
Box Click
Export
3. In the Save
As Dialog
Box Type in a descriptive
FileName and hit Save
Engineering/Math/Physics 25: Computational Methods
40
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
Engineering/Math/Physics 25: Computational Methods
41
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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 ClipBoard
1. Select Copy Options from the Edi t 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.
Engineering/Math/Physics 25: Computational Methods
42
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
1. In Figure 1
Window Click
Edit
→
Copy
Options...
Engineering/Math/Physics 25: Computational Methods
43
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
2. In the
Preferences
Dialog Box check the
Copy-Options
Boxes as you see Fit
3. Close the
Dialog Box
Engineering/Math/Physics 25: Computational Methods
44
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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.
Engineering/Math/Physics 25: Computational Methods
45
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
600
500
400
300
200
100
0
-100
-2 -1 0
Engineering/Math/Physics 25: Computational Methods
46
1 x
2 3 4 5
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
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.
Engineering/Math/Physics 25: Computational Methods
47
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
2 x
3
7 x
2
9 x
6 f
Bruce Mayer, PE
Licensed Electrical & Mechanical Engineer
BMayer@ChabotCollege.edu
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Plot_Mode_1.ppt
Engineering/Math/Physics 25: Computational Methods
48