ENGR-25_Lec-27_MuPAD_Intro
Download
Report
Transcript ENGR-25_Lec-27_MuPAD_Intro
Engr/Math/Physics 25
Chp11:
MuPAD
Bruce Mayer, PE
Licensed Electrical & Mechanical Engineer
[email protected]
Engineering/Math/Physics 25: Computational Methods
1
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Learning Goals
Understand and Open MuPAD
“NoteBooks”
Work within the NoteBooks to perform
SYMBOLIC CALCULATIONS including
• Algebra
• Transcendental Equations
• Calculus
• Ordinary
Differential
Equations
Engineering/Math/Physics 25: Computational Methods
2
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Chapter Sections NOT Covered
§4 → Matrix Operations
§7 → LaPlace Transforms
§8 → Special Functions
Carefully Study the Book for Syntax
• Learn MuPAD by
– “Stare & Compare” (examples)
– Hacking
– And, if all else fails, then HELP!
Engineering/Math/Physics 25: Computational Methods
3
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Learning Goals
Use MuPAD to create PLOTS of
functions
Engineering/Math/Physics 25: Computational Methods
4
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
MATLAB Symbolic MATH
In Addition to Using NUMBERS
MATLAB can Manipulate SYMBOLS
Basically, a Mathematics HandBook has
been codifed in Software by a group at
the University of Paderborn in Germany
The MathWORKS Purchased The
“MuPAD” Symbolic Math “Engine” (or
“Kernal”), and Integrated it into MATLAB
• MuPAD uses Pascal-like Syntax
Engineering/Math/Physics 25: Computational Methods
5
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
MuPAD → SYMBOLIC Calcs
MuPAD, sort of Like SimuLink, is a
program within-a Program
• SimuLink creates Icon-based “Models” (.mdl)
of Mathematical Systems
– SimuLink produces NUMERICAL Resuls
MuPAD creates “NoteBooks” (.mn) in
which SYMBOLIC quantities can be used
• The Symbols can be associated with NO
particular number value
– It’s similar to a Math Book that does the work
Engineering/Math/Physics 25: Computational Methods
6
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Symbolic Computation
The Differences Between Symbolic and
Numeric Computation
Numerical
Variables Represent
Numbers
Variables are Symbols; e.g., x,
y, z, β, θ, σ
Answers can Only be
Numbers
Answers can contain Variables
and Functions
Numeric Computation
can be done using
Standard Programming
Languages
Engineering/Math/Physics 25: Computational Methods
7
Symbolic
Symbolic computations are not
similar to standard programming
languages – they use symbolic
Manipulations
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
MuPAD BackGround
MuPAD is a part a generic class of
Software called a “Computer
Algebra System” (CAS).
• MuPAD research group at the University of
Paderborn, Germany originally developed
this symbolic-manipulation software
The MathWORKS purchased MuPAD to
replace the previous “Symbolic Math
Kernal” written by MapleSoft
Engineering/Math/Physics 25: Computational Methods
8
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Sample of MuPAD Capabilities
Create SYMBOLIC expressions and
manipulate them algebraically.
Obtain SYMBOLIC and numeric
solutions to algebraic and
transcendental equations.
Perform SYMBOLIC LINEAR
ALGEBRA operations, including
obtaining expressions for determinants,
matrix inverses, and others.
Engineering/Math/Physics 25: Computational Methods
9
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Sample of MuPAD Capabilities
Perform SYMBOLIC differentiation
and integration
Evaluate limits and series
SYMBOLICALLY.
Obtain SYMBOLIC solutions to Ordinary
Differential Equations (ODEs).
Solve ORDINARY DIFFERENTIAL
EQUATIONS in terms of special
functions or series.
Engineering/Math/Physics 25: Computational Methods
10
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
MuPAD “NoteBook”
MuPAD creates within MATLAB its own
working SubWindows Called NoteBooks
• The User works/types in the “NoteBooks”
• NoteBooks saved with extension: .mn
For MuPAD beginers it’s best start at
the MuPAD “Welcome” screen
At the MATLAB Command Prompt type
mupadwelcome
Engineering/Math/Physics 25: Computational Methods
11
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
mupadwelcome Screen
Suggest Spending Some time in the
“Getting Started” section
Engineering/Math/Physics 25: Computational Methods
12
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Go Directly to WorkBook
In MATLAB
command
window type
mupad
A MuPAD
NoteBook
Engineering/Math/Physics 25: Computational Methods
13
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
NoteBook Regions Calcs
CALC Regions
Engineering/Math/Physics 25: Computational Methods
14
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
NoteBook Regions Text
TEXT Regions
Engineering/Math/Physics 25: Computational Methods
15
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
NoteBook Regions OutPut
OutPut Regions
Engineering/Math/Physics 25: Computational Methods
16
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Importance of “Evaluation”
The CALCULATION regions in MuPAD
can be Inserted, Deleted, Edited
After Editing, We may have to
EVALUATE the edit using the TOOL or
PULL DOWN MENU
If a change in an OUTPUT Region does
NOT happen as expected; then be
SURE to EVALUATE the CALC region
• “EVALUATE ALL” often works best
Engineering/Math/Physics 25: Computational Methods
17
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Evaluate by TOOL
Place the cursor
IN the CALC
Region
Then Hit the
Evaluate Button
to initiate the
Calculation
Note also the
ASSIGNMENT
Operator →
:=
Engineering/Math/Physics 25: Computational Methods
18
After EVALUATE
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Evaluate Options
Use the PullDown Menu for
Different forms of
the
EVALUATION
Use the
NOTEBOOK
Pull-Down
• “Evalute All”
works well
Engineering/Math/Physics 25: Computational Methods
19
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
MuPAD Syntax & Structure
TEXT regions do
NOT have a left
Bracket
CALC & OUTPUT
Regions DO have a
Left Bracket
Engineering/Math/Physics 25: Computational Methods
20
Interaction with
INTEGERS
Produces a
SYMBOLIC OutPut
Using a decimal
Point Produces a
NUMBER Result
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
MuPAD Syntax & Structure
Reserved Symbols
Log Examples
PI
e
i j 1
E
I
The Logarithms
log b
Base - b log
ln
Base - e log
Engineering/Math/Physics 25: Computational Methods
21
A Decimal
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
FLOAT command
The float
command produces
a DECIMAL Result
for an otherwise
integer display
Engineering/Math/Physics 25: Computational Methods
22
Caveat on float(%)
The float(%)
command changes
the LAST
EVALUATED result
to a decimal; not
necessarily the value
right above (or below)
the float(%)
command
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Float(%) Confusion
Bottom Expression
Evaluated LAST
Engineering/Math/Physics 25: Computational Methods
23
First Expression
Edited then Eval’d
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Command Bar
ShortCuts to
Commands in:
The General Math Menu
Expand
Simplify
Factor
Combine
Normalize
Rewrite
Evaluate
Solve
Items on the Command bar
Derivatives
Integrals
Solve Equations
Numerical Evaluation and Rounding
Math Operators
Trig Functions
Reserved Symbols
Matrices and Vectors
Limits
Rewrite Expressions
Simplify
Equality Tests
Factorials
Exponentials and Logs
Greek Letters
2D Plot
Sums
Products
Evaluate with x = a
Assignment
Function Definition
Piecewise Definitions
Physical Units
3D Plot
Items on the
Command Bar use
# as a PlaceHolder
that MUST be
replaced
Engineering/Math/Physics 25: Computational Methods
24
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Expression vs. Function
An EXPRESSION
Example
A MuPAD Function is
called a Procedure
• Construction looks like
an anonymous fcn
– Use “->” in place of @
Engineering/Math/Physics 25: Computational Methods
25
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Plots are Easy
Plot from a
Procedure (UDF)
Plot from an
Expression
No SemiColon
Engineering/Math/Physics 25: Computational Methods
26
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Printing from MuPAD
Each NoteBook must
be Printed Separately
Use standard Windows
Pull-Down Menu:
• File → Print
These should appear in
all Notebks
• Student Name
• ENGR25
• HW Problem Number
• Date Created/Printed
Engineering/Math/Physics 25: Computational Methods
27
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Copy-n-Paste in MuPAD
The TEXT regions
can be copied &
pasted in the normal
fashion
In MSWord The
BLUE “Hand Math”
must be copied and
“Pasted Special” as
a “Device
Independent
Bitmap”
Engineering/Math/Physics 25: Computational Methods
28
In PPT A Plain
“Bitmap” PasteSpecial also works
Examples of the two
Bitmaps into PPT
shown below
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Copy-n-Paste in MuPAD
Pasting in MSWord requires TWO
Copy-n-Paste Operations
1. Paste TEXT Regions NORMALLY
2. Paste “Script Math” Using “Paste Special”
Engineering/Math/Physics 25: Computational Methods
29
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Copy-n-Paste in MuPAD
Copying GRAPHS
requires at THIRD
Operation
Click the Graph to
Activate the Plot
Menu Bar
Make the Graph
Engineering/Math/Physics 25: Computational Methods
30
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Copy-n-Paste in MuPAD
Use Pull-Down
Menu
Engineering/Math/Physics 25: Computational Methods
31
The Thick border
indicates graphic
has been copied to
the clipboard
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Copy-n-Paste in MuPAD
Then NORMAL Paste into Word
Engineering/Math/Physics 25: Computational Methods
32
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Copy-n-Paste in MuPAD
To AVOID All this Copy-n-Paste Hassle
• Simplest is to just PRINT the MuPAD
NoteBook
– Only get one Problem per sheet
• Do an alt+PrtScrn to copy the MuPAD
window, then paste the whole window into
MSWord
• Do an entire SCREEN-SHOT and crop it
back to the MuPAD part
– If MuPAD window not maximized
Engineering/Math/Physics 25: Computational Methods
33
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Engineering/Math/Physics 25: Computational Methods
34
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Example Algebra
Given Expressions
A y 15 y 75 y
3
2
B y 5 20 y
2
For This situation find
• The Product A∙B in Simplest Form
• The Quotient A/B in Simplest Form
• Evaluate A+B at y = 8.3 in
– Symbolic form
– Numeric form
Engineering/Math/Physics 25: Computational Methods
35
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Algebra Example
Engineering/Math/Physics 25: Computational Methods
36
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Solving Equation solve(eqn)
SOLVE
in here
Engineering/Math/Physics 25: Computational Methods
37
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Solve Systems of Eqns
Solve by MuPAD
1x
1y
2z
11
1x
1x
1y
2y
3z
1z
14
5
1
2
3
Note the use of
SQUARE Brackets
and
2x
4y
3z
17
x
4x
2y
y
z
z
0
6
Engineering/Math/Physics 25: Computational Methods
38
1
2
3
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
10
solve::numeric
5
X: -2.76
Y: 0.1141
X: 2.76
Y: 0.1141
0
Some eqns do NOT
have Algebraic
solution, such as
x
2
14 7 cos x
-5
-10
-15
-20
Solutions ≈ x = ±2.76
-25
-5
Solve by regular
MATLAB → fzero
Use fplot for
x 14 7 cos x 0
2
Engineering/Math/Physics 25: Computational Methods
39
-4
-3
-2
-1
0
1
2
3
4
5
ParabCos = @(x) x.^2-14 - 7*cos(x);
fplot(ParabCos,[-5 5]), grid
sL = fzero(ParabCos, -3)
sR = fzero(ParabCos, +3)
RESULT:
sL =
-2.7460
sR =
2.7460
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
solve::numeric
Now use numeric
modifier in MuPAD
Chk with MuPAD
No Symbol Soln
Only ONE Solution
LEFT Solution
Engineering/Math/Physics 25: Computational Methods
40
RIGHT Solution
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Formatting Plots
Make a plot, then
click the plot to
CHANGE the tool
Bar
Engineering/Math/Physics 25: Computational Methods
41
Click the “Object
Browser” Button
Explore the options
in the two boxes at
right (click upper
item first)
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
After some menu Exploration
Engineering/Math/Physics 25: Computational Methods
42
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
EXPORT Graphs
RIGHT Click the Graphic, then Follow
the “Wizard” instructions
Engineering/Math/Physics 25: Computational Methods
43
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Graph Export (JPEG) Result
Engineering/Math/Physics 25: Computational Methods
44
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Derivatives diff(f,x)
Engineering/Math/Physics 25: Computational Methods
45
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Example diff at a value
A chance to use the
subs command
Given:
u cosh 5v sinh(3v)
Find by MuPAD
du
dv v 0.3
Engineering/Math/Physics 25: Computational Methods
46
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Integrals
int(f,x)
Engineering/Math/Physics 25: Computational Methods
47
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
ODEs solve(ode(#, #(#)))
Engineering/Math/Physics 25: Computational Methods
48
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Example assume
Solve this ODE
d2y
ky 0
2
dx
The assume
command notifies
MuPAD about the
Constraint
With Boundary
Conditions
y 0 1
dy
dx x 0 0
With Constraint
k 0
Engineering/Math/Physics 25: Computational Methods
49
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
All Done for Today
MuPAD
used to
be Free
A 523 Page MuPAD Tutorial
http://www.calvin.edu/~tmk5/research/mupad_tutorial.pdf
Engineering/Math/Physics 25: Computational Methods
50
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Engr/Math/Physics 25
Appendix
f x 2 x 7 x 9 x 6
3
2
5 y 3 y 7 y f t
Bruce Mayer, PE
Licensed Electrical & Mechanical Engineer
[email protected]
Engineering/Math/Physics 25: Computational Methods
51
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt
Tutorial on Plot Formating
Use
ENGR25_MuPAD_t
utorial_format_plot_
1111.mn
Solve Make Graph
Format with
OBJECT
BROWSER tool
Engineering/Math/Physics 25: Computational Methods
52
Bruce Mayer, PE
[email protected] • ENGR-25_Lec-25_SimuLink-2.ppt