Академический Документы
Профессиональный Документы
Культура Документы
APPLICATION
Linear Algebra
Solving A Linear System
Gaussian Elimination
Finding Eigenvalues and Eigenvectors
Matrix Factorization
Curve Fitting and Interpolation
Polynomial Curve Fitting on the Fly
Curve Fitting with polynomial Functions
Least Squares Curve Fitting
General Nonlinear Fits
Interpolation
Data Analysis and Interpolation
Numerical Integration
Ordinary Differential Equations
First Order ODE
Second Order Nonlinear ODE
ODE23 vs ODE45
Specifying Tolerances
The ODE Suite
Event Location
APPLICATION
Nonlinear Algebraic Equation
Roots of Polynomials
Vibration Analysis
Time Domain
Frequency Domain
Introduction to FFT
LINEAR ALGEBRA
Solving A Linear System
5x = 3y - 2z + 10
8y + 4z = 3x + 20
2x + 4y - 9z = 9
Rearrange equations
5x - 3y + 2z = 10
-3x + 8y + 4z = 20
2x + 4y - 9z = 9
Write the equations in matrix form:
[A]{x} = {b}
LINEAR ALGEBRA
Solving A Linear System
Solve the matrix equation in MATLAB
LINEAR ALGEBRA
Gaussian Elimination
In introductory linear algebra courses, we learn to solve a system of linear algebraic equations by Gaussian
elimination.
This technique requires forming a rectangular matrix that contains both the coefficient matrix A and the known
vector b in an augmented matrix.
Gauss-Jordan reduction procedure is then used to transform the augmented matrix to the so-called row reduced
echelon form
MATLAB has a built in function, rref, that does precisely this reduction, i .e . , transforms the matrix to its row reduced echelon
form.
LINEAR ALGEBRA
Gaussian Elimination
LINEAR ALGEBRA
Finding Eigenvalues and Eigenvectors
An eigenvector or characteristic vector of a square matrix A is a non-zero vector v that, when multiplied with A, yields a scalar
multiple of itself; the scalar multiplier is often denoted by lambda.
=
LINEAR ALGEBRA
Finding Eigenvalues and Eigenvectors
LINEAR ALGEBRA
Matrix Factorization
LU Factorization
[L U] = lu(A)
QR Factorization
[Q R] = lu(A)
Cholesky Factorization
R= chol(A)
For polynomial curve fits , of any order n , the problem is to find the (n + 1 ) coefficients an, an-1 , an-2, a1 , and ao, from
the given data of length (n + 1 ) or more.
MATLAB provides an easy way-through the built-in functions polyfit and polyval.
polyval
Given a data vector x and the coefficients of a polynomial in a row vector a , the command y = polyval ( a , x) evaluates the
polynomial at the data points X i and generates the values Yi such that
Here the length of the vector a is n + 1 and, consequently, the order of the evaluated polynomial is n . Thus if a is five
elements long, the polynomial to be evaluated is automatically ascertained to be of fourth order
We can convert these exponential curve fits into polynomial curve fits (actually a linear one) by taking the log of both
sides of the equations
Now we can use polyfit in both cases with just first-order polynomials to determine the unknown constants
Step 2 : Do a linear fit : Use polyfit to find the coefficients a0 and a1 for a linear curve fit
Step 3 : Plot the curve : From the curve fit coefficients, calculate the values of the original constants (e.g. , a, b) . Recompute the
values of y at the given x's according to the relationship obtained and plot the curve along with the original data
= 0
Now you can solve for the unknowns a0 and a1 simply by typing a=A \x where A is
the coefficient matrix and x is the vector containing the measured data Xi . Typically,
A is a rectangular matrix and the matrix equation to be solved is overdetermined
(more independent equations than unknowns) . This, however, poses no problem,
because the backslash operator in MATLAB solves the equation in a least squares
sense whenever the matrix is rectangular
Interpolation
When we want to pass a smooth curve through these points or find some intermediate points, we use the technique of
interpolation.
Interpolation is NOT curve fitting, in that it requires the interpolated curve to pass through all the data points
Interp1
One-dimensional data interpolation, i.e. , given Yi at xi , finds Y] at desired Xj from '!/j = j(x j). Here f is a continuous function that
is found from interpolation. It is called one-dimensional interpolation because y depends on a single variable :r. The calling syntax
is
interp2
Two-dimensional data interpolation, i.e. , given zi at (xi , Yi ) , finds Zj at desired (xj , yj ) from z = j ( x , y) . The function f is found
from interpolation. It is called two-dimenl:lional interpolation because z depends on two variables, x and y .
Interpolation
interp3
Three-dimensional analogue of int e rp 1 , i .e . , given Vi at (xi,
Interpolation
There are two simple steps involved in interpolation-providing a list (a vector) of points at which you wish to get interpolated data
(this lis
t may
include points at
which data is already available), and executing the appropriate function (e.g. , int erp 1 ) with
the desired choice for the method of interpolation. We illustrate these steps through an example on the x and y data given in tbe following tabl
Caution: In all interpolation functions, it is required that the input data points in x be monotonic (i.e. , either continuously
increasing or decreasing)
For performing simple data analysis tasks, such as finding mean, median, and standard deviation, MATLAB provides an easy
graphical interface that you can activate from the Tools menu of the figure window
First , you should plot your data in the form you wish (e.g. , scatter plot , line plot)
Then, go to the figure window and select Data Statistics from the Tools pull-down menu
MATLAB shows you the basic statistics of your data in a separate window marked Data Statistics
You can show any of the statistical measures on your plot by checking the appropriate box
built-in functions
median gives the middle value or the arithmetic mean of the two middle values of the data.
Example: median (x) gives 3 while median (A) gives [8 3 0]
std gives the standard deviation based on n - 1 samples
Example: std ( x ) gives 1 . 58 1 1
max finds the largest value in the data set
Example: max ( x ) gives 5 and max ( A ) gives [10 5 2]
min finds the smallest value in the data set
Example: min ( x ) gives 1 and min ( A ) gives [6 2 - 2]
built-in functions
built-in functions
Specifying tolerance
A tolerance is a small positive number that governs the error of some appropriate kind in the computations of that function
Event location
In solving initial value problems, usually the termination condition is specified in terms of the independent variable.
As shown in the previous Lwo examples, the solution stops when the independent variable t reaches a prescribed value tfinal
(specified as the second element of t span) .
Sometimes , however, we need to stop the solution at a specified value of the dependent variable and we do not know when (at
what value of t) the solution will reach there.
The MATLAB function fzero solves nonlinear equations involving one variable
Roots of polynomials
You can also find the zeros of a polynomial equation with fzero.
However, fzero locates the root closest to the initial guess; it does not give all roots.
To find all roots of a polynomial equation, use the built-in function roots . This function requires the coefficients of the powers of
x (in decreasing order) , including the constant in a vector and gives all the roots as the output