50 views

Uploaded by Gaurav Kumar

matlab and its application in genearal.
matlab basics.

- Lec 7 First Order Fluid
- POLYMATH TutorialChemical Reaction Engineering(1)
- CRE Assignment.xlsx
- Uniform Order Legendre Approach for Continuous Hybrid Block Methods for the Solution of First Order Ordinary Differential Equations
- [ozgur]-lecture 5 (2.6)
- Differential Equations
- Mining Hazard2
- Project 1
- APPLICATIONS OF GENERALIZED INVERSES BOTH IN HOMOGENEOUS AND NON-HOMOGENEOUS SYSTEM OF LINEAR EQUATIONS.
- up
- up
- Topic 3c Interpolation
- De Module(2009 Edition)
- amie section A
- MN.pdf
- c16-0
- Matlab Examples
- FinalExamSchedule-Spring2013-v2.0 (1).pdf
- Process Modelling and Simulation
- Guidelines for the Course

You are on page 1of 43

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)

Polynomial Curve Fitting

Curve fitting is a technique of finding an algebraic relationship that best fits a given set of data.

Unfortunately, there is no magical function (in MATLAB or otherwise) that can give you this relationship if you simply supply

the data You have to have an idea of what kind of relationship might exist between the input data and the output data.

However, if you do not have a firm idea but you have data that you trust , MATLAB can help you explore the best possible

Fit

MATLAB includes Basic Fitting in its figure window's Tools menu that lets you fit a polynomial curve (up to the tenth order) to

your data

It also gives you options of displaying the residual at the data points and computing the norm of the residuals

This can help in comparing different fits and then selecting the one that makes you happy

Straight-line (linear) fit

Let us say that we have the following data for x and y and we want to get the best linear (straight-line) fit through this data.

Straight-line (linear) fit

Comparing different fits

Lets try two different fits, quadratic and cubic

Go to your figure window, click on Tools, and select Basic Fitting from the pull-down menu. In the Basic Fitting window, check

quadratic and cubic boxes. In addition, check the boxes for Show equations, Plot residuals , and Show norm of residuals

Curve fitting with polynomial functions

In MATLAB, it is fairly easy to do polynomial curve fits using built-in polynomial functions and get the desired coefficients.

The simplest relationship between two variables, say x and y, is a linear relationship: y = mx + c. For a given set of data points

(xi, Yi), the problem is to find m and c such that Yi = mxi + c best fits the data.

For data points that are not linearly related, you may seek a polynomial relationship or an exponential relationship

or even more complicated relationships involving logarithms , exponentials, and trigonometric functions.

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.

Curve fitting with polynomial functions

Polyfit

Given two vectors x and y , the command a = polyfit( x , y , n) fits a polynomial of order n through the data points (xi, Yi) and

rreturns (n+ 1 ) coefficients of the powers of x in the row vector a.

The coefficients are arranged in the decreasing order of the powers of x, i .e .,

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

Straight-line (linear) fit

Straight-line (linear) fit

Non-polynomial function fit

The most commonly used functions are

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

Non-polynomial function fit

Step 1 : Prepare new data

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

Non-polynomial function fit

Example

The following table shows the time versus pressure variation readings from a vacuum pump

= 0

Non-polynomial function fit

Non-polynomial function fit

There is yet another way to fit a complicated function through your data in the least squares sense. For example, let us say that

you have time (t) and displacement (y) data from a spring-mass system experiment and you think that the data should Follow

The equation is nonlinear in t but linear- in the parameters a0 and a1 Therefore, you can set up a matrix equation using each

data point and solve for the unknown coefficients

The matrix equation is

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

Example: mean (x) gives 3 while mean (A) results in [8 3.2 0]

x

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

Cumsum computes cumulative sum.

Example: cumsum (x) produces [1 3 6 1 0 1 5] .

Prod computes the product TI Xi of all data values .

Example: prod ( x ) gives 120 and prod ( A ) gives [30240 2 4 0 0] .

Example: cumprod ( x ) produces [1 2 6 24 120]

Sort sorts the data in ascending (default) or descending order. An optional

output argument (e.g. , [y , k] =sort (x) ) gives the indices of the sorted data

Values

built-in functions

Q = quad(FUN,A,B,TOL)

For ODEs of order :?: 2 , this step involves introducing new variables and recasting the original equation(s) in terms of first-order

ODEs in the new variables.

to solve the equations

interpret the results

Step 1 : Write the equation(s) as a system of first-order equations :

The given equation is already a first-order equation. No change is required.

The function should return x given x and t. Here is the function:

Write and save it as an M-file named simpode . m

Step 1 : Write the equation(s) as a system of first-order equations:

The given equation is a second-order ODE. To recast it as a system of two firstorder equations (an nth order equation reduces to a set

We need to write a function that, given the scalar time t and vector z as input , returns the time derivative vector as output .

Now, let us write a script file that solve the system and plots the results .

Remember that the output z contains two columns : Zl , which is actually , and Z2 , which is .

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

Use the built-in function fzero to find the solution

fzero requires an initial guess and returns the value of x closest to the guess at which f(x) is zero. The function written in Step 2 is

used as an input to the function

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

- Lec 7 First Order FluidUploaded byمحمد سعيد
- POLYMATH TutorialChemical Reaction Engineering(1)Uploaded byAnonymous ox8Tn9
- CRE Assignment.xlsxUploaded byGhulam Murtaza
- Uniform Order Legendre Approach for Continuous Hybrid Block Methods for the Solution of First Order Ordinary Differential EquationsUploaded byInternational Organization of Scientific Research (IOSR)
- [ozgur]-lecture 5 (2.6)Uploaded byOrkun Akyol
- Differential EquationsUploaded bykothapalli21
- Mining Hazard2Uploaded byIrfanMarwanza
- Project 1Uploaded bylikpata
- APPLICATIONS OF GENERALIZED INVERSES BOTH IN HOMOGENEOUS AND NON-HOMOGENEOUS SYSTEM OF LINEAR EQUATIONS.Uploaded byIJAR Journal
- upUploaded bybashasvuce
- upUploaded bybashasvuce
- Topic 3c InterpolationUploaded byFarhana Hussin
- De Module(2009 Edition)Uploaded byNor Syahirah Mohamad
- amie section AUploaded byrao_gsv7598
- MN.pdfUploaded bySujit Kumar
- c16-0Uploaded byVinay Gupta
- Matlab ExamplesUploaded byNozes Da Castanha
- FinalExamSchedule-Spring2013-v2.0 (1).pdfUploaded byHashim Rashid
- Process Modelling and SimulationUploaded byVishal Gupta
- Guidelines for the CourseUploaded byMaruthi Ram
- KTH, DN2221, Computer Lab 2Uploaded bysebastian
- 240 SyllabusUploaded byScott Middleton
- Numerical Solution of Differential EquationsUploaded bymohammed taha
- Modeling and s FunctionUploaded byneyzenapo
- lec02Uploaded bySonam Behl Kamboj
- LHY_Scilab_Xcos_Tutorial_Part2_0Uploaded byCarlos Soza Ross
- tt18Uploaded byggf
- 10-10-Spring 2009-SyllabusUploaded byTim
- 1st Prac PDFUploaded byRahul Massey
- 1-s2.0-S1359836801000415-mainUploaded bySaam Sasanian

- matematica.docxUploaded bycesar1hc
- k – Means ClusteringUploaded byeerdemss
- ED_de_movimiento-Ley_visc_Newton-Soluciones_Navier-Stokes-C1_2008-PublicadoUploaded byeccbiotesis
- JEE-Main-2018_paper2.pdfUploaded byShailendra Jakhar
- Https Attachment.fbsbx.com File DownloadUploaded byKishore Shetty
- SURVEY ON APPLICATION OF LAGRANGIAN RELAXATION, INTERIOR POINT AND DYNAMIC PROGRAMMING FOR THE SOLUTION OF HYDROTHERMAL SCHEDULINGUploaded byUmair Saif
- 123 INTEGRALES ELEMENTALESUploaded byRobin Reyes
- SigmaUploaded byAlpha
- Central 11-08-13 ISC Board Test-1 Phy(Projectile Motion Motion in Straight) Sol KDp SirUploaded byPrithviraj Netke
- Fractional Integration OperatorUploaded byHenrique Lima
- Lectures on Stochastic AnalysisUploaded byaufernugas
- CM-G.pdfUploaded byShweta Sridhar
- accelerated algebra one scope sequenceUploaded byapi-263209117
- The Quadratic Formula ExplainedUploaded byIvanLee
- CHEE319_quiz1solu_2011Uploaded bysunlias
- Tangent Equation of a Circle PPT 1Uploaded byAbdullah Aziz Alaika
- Chapter 1 (Preliminaries)Uploaded byAmmar Ajmal
- Lecture_vector_sUploaded byLemdy Anwuna
- Finite_difference_Heat.docxUploaded byGilberto Roman
- Add Math Spm Trial 2013 Kelantan Smkanaimlilbanat p2 AnsUploaded byezza_jaja83
- art%3A10.1007%2Fs11370-014-0152-zUploaded bymaklemz
- Bootstrap Methods: Another Look at the JackknifeUploaded byJeiel França
- If Y is a proper finite dimensional subspace of normed space X, then dist(x,Y)=1Uploaded byRishabh Sarma
- JEHLE RENY Solutions to Selected ExercisesUploaded bySyed Yusuf Saadat
- Z Transform Table - RheaUploaded bytt_aljobory3911
- Quaternions BrieflyUploaded byTed Bagg
- 12th syllabus___(1)Uploaded byN C Nagesh Prasad
- Boolean Functions and Artificial Neural NetworksUploaded byminhthangbk
- 2004OYPhdThesisUploaded byChandra Mohan Gaddam
- A1.2 - Perms and CombosUploaded byamolkhadse