View
6
Download
0
Category
Preview:
Citation preview
MAE 4020/5020 – Numerical Methods with MATLAB
SECTION 1: INTRODUCTION
Mathematical Models2
K. Webb MAE 4020/5020
3
Models
K. Webb MAE 4020/5020
As engineers, we are interested in analyzing and designing physical systems
We represent these systems with models: Abstracted representation of the real system Captures some of the real system’s behavior – the behavior we care about
Simplified in some way Smaller Less complex Linear Lossless, etc. …
4
Mathematical Models
K. Webb MAE 4020/5020
Model of a physical system may be: A physical system itself, simplified in some way e.g., scale model for wind‐tunnel testing
A mathematical model An equation or system of equations that describe the aspects of system behavior that interest us (while ignoring others)
A physical model as an intermediate step in generating a mathematical model An abstraction of the real system, whose behavior we can describe with mathematical expressions
Mathematical Models5
K. Webb MAE 4020/5020
6
Modeling Example
K. Webb MAE 4020/5020
Vehicle suspension design – quarter‐car model Simplification of the overall vehicle
Considers only one wheel (one quarter of the car) at a time
Elements may be assumed linear (or not)
Accounts for car body, shock absorbers, wheel, and tire
Road surface provides displacement input
7
Modeling Example
K. Webb MAE 4020/5020
By applying Newton’s second law to our simplified physical model, we can generate a mathematical model for our system
The resulting mathematical model is a pair of coupled second‐order differential equations:
0
8
Modeling Example
K. Webb MAE 4020/5020
Can rearrange into a single fourth‐order ODE Or, express in state‐space form:
In all forms, the model describes the relationship between: Output (dependent variable) – (e.g. xs(t), in our example) Independent variable – (e.g. t) Input (forcing function) – (e.g. xr(t))
Dependent on parameters – (e.g. k, b, kt, ms, and mus) Model (or it’s solution) has the form:
. . , ,
9
Modeling Example
K. Webb MAE 4020/5020
The resulting mathematical model can be solved analytically Tractable, though tedious for this fourth‐order system
Solution is well‐suited to numerical analysis using MATLAB or similar tool
Quickly and easily determine system response to various inputs e.g., how does the suspension respond to driving over a bump
See the effects of system parameters e.g., spring constant, damping coefficient
10
Numerical Solution to Our Mathematical Model
K. Webb MAE 4020/5020
11
Parametric Analysis
K. Webb MAE 4020/5020
12
Parametric Analysis – Waterfall Plot
K. Webb MAE 4020/5020
13
Parametric Analysis – Surface plot
K. Webb MAE 4020/5020
14
Visualization of Numerical Solution ‐ Animation
K. Webb MAE 4020/5020
Introduction to MATLAB15
K. Webb MAE 4020/5020
16
The MATLAB Desktop
K. Webb MAE 4020/5020
Workspace
FileBrowser
CommandHistory
17
The MATLAB Desktop – Command Window
K. Webb MAE 4020/5020
Command‐line operation Behaves like a calculator
Useful for: Quick calculations Simple debugging tasks
18
The MATLAB Desktop – Editor Window
K. Webb MAE 4020/5020
Editor for m‐files Scripts Functions
Built‐in debugger Set breakpoints Step through code line‐by‐line or by section
19
The MATLAB Desktop – Workspace
K. Webb MAE 4020/5020
Lists all variables currently stored in memory Values for scalars and small arrays
Size and data types for larger arrays
Double‐click a variable to open in a spreadsheet
20
The MATLAB Desktop – Current Folder
K. Webb MAE 4020/5020
File browser A built‐in ‘Windows Explorer’
Open, move, copy, rename, delete files from within MATLAB
21
The MATLAB Desktop – Command History
K. Webb MAE 4020/5020
Lists previously‐executed commands All commands issued through the command window
Double‐click to re‐execute
Arrow keys cycle through command history in the command window
22
The MATLAB Desktop – Docking Windows
K. Webb MAE 4020/5020
23
The MATLAB Desktop – Docking Windows
K. Webb MAE 4020/5020
Docked windowsstay on top of the desktopWon’t get hidden below other windows
Can dock figure windows as well
24
The MATLAB Desktop – Saving Layouts
K. Webb MAE 4020/5020
Favorite desktop configuration or configurations can be saved
25
Assignment of Variables
K. Webb MAE 4020/5020
Can define variables and assign values
Variable and value echoed in command window
Terminating command with semicolon suppresses echo
Variables then appear in workspace
26
Scalars, Arrays, Vectors, and Matrices
K. Webb MAE 4020/5020
MATLAB treats all variables as matrices or arrays The MAT in MATLAB is for MATrix (not MAThematics)
Matrix m x n array of values – m rows, n columns
Scalar 1 x 1 matrix
Vectors 1 x n matrix – one row, n columns – a row vector m x 1 matrix – m rows, 1 column – a column vector
Multi‐dimensional array m x n x p array – an array of p m x n matrices
27
Vectors and Matrices
K. Webb MAE 4020/5020
Arrays are enclosed in square brackets
Row vector Commas separate entries on the same rows
Column vector Semicolons separate rows
A 3 x 3 matrix
28
Vectors and Matrices
K. Webb MAE 4020/5020
The entries in an array can be arrays themselves
Must conform to size of other entries All entries on a row must have same number of rows
All entries on a column must have same number of columns
Here, A and B are being put on same row, but A has 1 row, while B has 3
29
Strings
K. Webb MAE 4020/5020
In addition to numeric data types, MATLAB supports the use of strings Variables whose values are text strings
Enclose strings in single quotes, e.g. ‘a string’
Many MATLAB functions require string input arguments, e.g. filenames, plot annotation, etc.
30
Mathematical Operations
K. Webb MAE 4020/5020
All the usual mathematical operations are supported
Operate on numbers or on variables
Again, default variable type is a matrix Operations on matrices are not the same as on scalars
More to come in a few slides, but must be careful
31
Built‐In Functions and Constants
K. Webb MAE 4020/5020
Default logarithm is natural log Specify base 2 or 10 if desired
Trigonometric functions assume arguments in radians
Append a ‘d’ to trigonometric functions for input/output in degrees
32
Built‐In Functions and Constants
K. Webb MAE 4020/5020
Pi ( ) is a built‐in constant in MATLAB
i and j are both defined as the imaginary unit ( )
Built‐in constants can be redefined Constants will revert to their default values when workspace memory is cleared
33
Array Generation – Colon Operator
K. Webb MAE 4020/5020
Here, we define a row vector of values from 1 to 8, incremented by 1
Can also set the increment value to something other than 1
Increment value need not be positive
34
Array Generation – ones(), zeros()
K. Webb MAE 4020/5020
Often need to create arrays of all 1’s or all zeros
ones(m,n) creates a vector of all 1’s with m rows and n columns
zeros(m,n) creates an m x n matrix of all 0’s
ones(N) or zeros(N) generates N x N matrices
35
Indexing Arrays
K. Webb MAE 4020/5020
Access individual elements or ranges of elements in an array by using subscript notation, e.g.:
, is the element from the row and the column In MATLAB: A(2,3) is the element in the 2nd row, 3rd column of A
Use colon operator for ranges of rows or columns e.g. A(1:3,2:5) represents entries in rows 1 – 3 and columns 2 –5.
A(:,2) represents the elements in all rows, 2nd column of A
36
Array Size functions
K. Webb MAE 4020/5020
size(A) returns a 1 x 2 vector containing the number of rows and columns of A
length(A) returns the largest dimension of A length(A)= max(size(A)) Useful for vectors
end is the last possible indexing value Row or column depending on what it is used to index
The following is a brief review of some very basic linear algebra concepts. We will return to more advanced topics in linear algebra later on in the course.
Linear Algebra Fundamentals37
K. Webb MAE 4020/5020
38
Matrix Addition and Subtraction
K. Webb MAE 4020/5020
As long as matrices have the same dimensions, we can add or subtract them Addition is done element‐by‐element, and the resulting matrix is the same size
We can also add scalars to matrices
39
Matrix Multiplication
K. Webb MAE 4020/5020
In order to multiply matrices their inner dimensionsmust agree
We can multiply only if the number of columns of is equal to the number of rows of
Resulting Matrix has same number of rows as and same number of columns as
(m x n) (n x p) (m x p) ∙
40
Matrix Multiplication
K. Webb MAE 4020/5020
The entry of is the dot product of the row of with the column of
41
Matrix Multiplication
K. Webb MAE 4020/5020
Remember, matrices don’t need to be the same size, but their inner dimensions must agree
Matrix multiplication is not commutative, i.e., order matters. In general
42
Vector Multiplication
K. Webb MAE 4020/5020
Two types of vector multiplication: Inner product (dot product)
Result is a scalar
Outer product Result for n‐vectors is an n x n matrix
43
Matrix ‘Division’ – Multiplication by the Inverse
K. Webb MAE 4020/5020
Scalar division that we are accustomed to can be thought of as multiplication by an inverse:
This is how we ‘divide’ matrices as well
Multiplication of a scalar by its inverse is equal to 1. For a matrix, the result is the identity matrix
44
Matrix Inverse
K. Webb MAE 4020/5020
Again, recall that matrix multiplication is not commutative Right‐multiplication is not the same as left‐multiplication
The inverse does not exist for some matrices If not, matrix is singularMust be full rank Non‐squarematrices are rank deficient, so are not invertible
45
Matrix Inverse in MATLAB
K. Webb MAE 4020/5020
Use inv(…) to generate a matrix inverse
A matrix times its inverse is the identity matrix
Can also use the left‐divideoperator (backslash) If exists, then
\ If does not exist, then left‐division means something different. We’ll come back to this later.
46
Exponentiation
K. Webb MAE 4020/5020
As with scalars, raising a matrix to the power, n, is the multiplication of that matrix by itself n times
What must be true of a matrix for exponentiation to be allowable?
Inner matrix dimensions must agree Rows of must equal columns of – n x nMatrix must be square
47
The MATLAB ‘Dot’ Operator
K. Webb MAE 4020/5020
Multiply, divide, exponentiate, etc. matrices element‐by‐elementMatrix dimensions (not just inner dimensions) must agree
Use the dot operator:
For example:
48
Passing Matrices to Functions
K. Webb MAE 4020/5020
Built‐in MATLAB functions (e.g., cos(…), exp(…), sqrt(…), log(…), etc.) will operate on matrices
The function is applied element‐by‐element Some functions also have special matrix versions, e.g. expm(…), sqrtm(…)
Recommended