By
Dr. R. R. Manza
Objectives
• Introduction
• Matrices
• Linear Equations
• Factorization
• Eigenvalues
• Polynomials
• Interpolation
• Data Analysis
• Polynomial Regression
• Basic Fitting
• Fourier approximation
• Integration and Differentiation
• Differentiation Equation
• Summary
1 0 0 0 > D=I*A
0 1 0 0
0 0 1 0 D=
0 0 0 1
16 2 3 13
>> A=magic(4) 5 11 10 8
9 7 6 12
A= 4 14 15 1
In the above example elements of matrix A and
elements of matrix C and D are the same. The
16 2 3 13 function eye is used to create rectangular or
5 11 10 8 square identity matrix.
9 7 6 12
4 14 15 1
5/16/2013 Dept of CS & IT Dr. BAMU Aurangabad 5
Cont..
Kronecker Tensor product: The kron >> C=kron(A,I)
function is used to determine kronecker
tensor product of two matrices in C=
MATLAB. The resultant matrix of this
function will be double in size than the
matrix used as an input. This function is 8 0 1 0 6 0
used to build repeated copies of small 0 8 0 1 0 6
matrices of zeros and ones. For example, 3 0 5 0 7 0
0 3 0 5 0 7
>> A=magic(3) 4 0 9 0 2 0
0 4 0 9 0 2
A=
>> C=kron(I,A)
8 1 6
3 5 7 C=
4 9 2
8 1 6 0 0 0
>> I=eye(2) 3 5 7 0 0 0
4 9 2 0 0 0
I= 0 0 0 8 1 6
0 0 0 3 5 7
1 0 0 0 0 4 9 2
0 1
5/16/2013 Dept of CS & IT Dr. BAMU Aurangabad 6
Cont..
Vector and Matrix norms: The norm function is used to compute the norm of a
vector or matrix. For example norm(x,p) is used to compute the p-norm of vector x.
which is defined by any value of p greater than one. The most common values of p
are one, two and infinity. The default value of p is two, which corresponds to
Euclidean length.
>> x=1:2:10
x=
1 3 5 7 9
>> norm(x)
ans =
12.8452
>> norm(x,1)
ans =
25
>> norm(x,inf)
ans =
X=
>> det(X)
ans =
-0.0154
Because of the above properties 1 through 4, all the equalities of equation (1) to (4) are the same as
the given equation. Hence 8/3 is the solution of the given equation.
We can verify the solution by substituting x = 8/3 in both sides of the given equation, getting 72 on
both sides. Thus LHS = RHS for x = 8/3. Therefore, 8/3 is the solution of the given equation.
Note that when we added –3x to both sides of equation (2), the effect was to make 6x on the RHS
equal to 3x – 3x = 0. Thus, 3x disappeared from the right and appeared on the left with its sign
changed is called transposition or transposing a term from one side to the other.
>> plot(x,y)
1) Cholesky Factorization
2) LU Factorization
3) QR Factorization
8 1 6
3 5 7
4 9 2
>> [Q,R,P]=qr(A)
Q=
-0.8480 0.5223 0.0901
-0.3180 -0.3655 -0.8748
-0.4240 -0.7705 0.4760
R=
-9.4340 -6.2540 -8.1620
0 -8.2394 -0.9655
0 0 -4.6314
P=
0 0 1
1 0 0
0 1 0
5/16/2013 Dept of CS & IT Dr. BAMU Aurangabad 22
Eigenvalues
An eigenvalue and eigenvector of a 3 0 2 4
square matrix A are a scalar λ and a 9 8 7 6
vector v that satisfy Av=λv. With >> eig_vector=eig(X)
eigenvalue on the diagonal matrix
Λ and the corresponding eig_vector =
eigenvectors forming the columns
of matrix V by AV=V Λ; if V is non- 13.4902
singular then this becomes the -2.7739
eigenvalue decomposition.
Example: 1.1418 + 2.3758i
>> X=[1 3 7 -2; 5 4 3 2; 3 0 2 4; 9 8 7 6] 1.1418 - 2.3758i
With two output arguments eig
X= function computes the
eigenvectors and stores the
eigenvalues in a diagonal matrix.
1 3 7 -2
5 4 3 2
V=
D=
13.4902 0 0 0
0 -2.7739 0 0
0 0 1.1418 + 2.3758i 0
0 0 0 1.1418 - 2.3758i
The first two eigenvectors are real and the other two vectors are complex
conjugates of each other.
5/16/2013 Dept of CS & IT Dr. BAMU Aurangabad 24
Polynomials
Polynomials are used in many applications of polynomials are represented by row vectors
engineering and science like curve fitting, containing coefficients ordered by descending
characterizing dynamic system and linear powers. For example
systems, mechanical devices, structures and
electrical circuits. Therefore polynomials are
widely applicable to solve many engineering
and science problems. The general form of To enter this polynomial into MATLAB the
polynomial equation is following statement is used
>>p=[1 –3 –2 1 10]
p=
where n is the order of the polynomial and a is
the constant coefficients. 1 -3 -2 1 10
To determine a single root of an nth order The roots function of MATLAB calculates the
polynomial we have to repeat root location roots of polynomial and stores in column
procedure; it may give the same root. vector.
Therefore, it would be nice to remove the
found root before proceeding. This removal
process is referred to as polynomial deflation.
Polynomials are typically represented in their
order format. For example a fifth order
polynomial could be written as
P1 = ans =
2 -6 -6 9 21 -4 -19 10
Deconvolution of these polynomials is
are the polynomials. To compute their computed by deconv function
product by using conv function >> [q r]=deconv(P,Q)
>> P=[2 0 -2 1] q=
P= 0
2 0 -2 1
r=
>> Q=[1 -3 -2 1 10]
2 0 -2 1
Q=
1 -3 -2 1 10
5/16/2013 Dept of CS & IT Dr. BAMU Aurangabad 28
Cont..
The polyder function of polynomials. c=
MATLAB is used to
compute the derivative 8 -15 -44 0
of the polynomial
equation; for example,
to calculate the to calculate the
>> p=[1 2 5 1] derivative of the product derivative of quotient.
> a=[2 5 1] >> [q,d]=polyder(a,b)
p=
a= q=
1 2 5 1
2 5 1 -15 2 10
>> D=polyder(p) d=
>> b=[1 -5 1] 1 -10 27 -10 1
D=
b=
3 4 5
polyder function is also 1 -5 1
used to compute the
derivative of the product >> c=polyder(a,b)
or quotient of two
5/16/2013 Dept of CS & IT Dr. BAMU Aurangabad 29
Cont..
Similarly, polyint function is used to >>x=[5 4 3 2 1 0];
calculate integral of a polynomial; it is >>y=[1.4 5.3 7 9.9 19.5 25.5];
easy to express.
>> I=polyint(a) >> p=polyfit(x,y,2) % Second order
I= polynomial to fit approximately the
0.6667 2.5000 1.0000 0 data values.
p=
polyfit finds the coefficients of
polynomial that fits a set of data in a 1.1000 -9.6600 23.6400
least squares format. Syntax: %compute the values of the polyfit
p=polyfit(x,y, n) estimate over a finer range and plot
the estimate over %the real data values
Where, x and y are vectors containing for comparison
the x and y data that to be fit and n is >> x1=1:0.1:5;
the order of the polynomial. For >> y1=polyval(p,x1);
example, consider x and y data >> plot(x,y,'*',x1,y1)
yi = interp1(x,y,xi,method)
Where, y is a vector containing the values of function, x is the vector of the same length
containing the points for which the values in y are given. xi is a vector containing the points at
which to interpolate. The method is an optional string specifying an interpolation method.
Y=interpft(x,n),
>> [x y]=meshgrid(-4:1:4);
>> z=peaks(x,y);
>> surf(x,y,z)
ans =
3261.6
Example:
Consider the curve parameterized by the equations x(t)=sign(2t), y(t)=cos(t) and
z(t)=t; where, ; 3-D plot of this curve is
>> t=0:.1:3*pi;
>> plot3(sin(2*t),cos(t),t)
The equation states that the first derivative of the function y equals the product of
Where,
• pdefun is a component of the PDE and computes as [c,f,s]=pdefun(x,t,u,dudx), where x and t are scalars and u and
dudx are vectors.
• icfn is of the form u=icfm(x) and used to evaluate the initial values of the solution components at x in the column
vector u.
• bcfun is used to evaluate the terms p and q of the boundary conditions. [pl,ql,pr,qr]=bcfun(xl, ul, xr, ur, t)
• tspan is used to specify the span at which the solution is requested for every value in x mesh.
The output of pdepe function is a three dimensional array, whose first dimension is to store approximate component
of the solution u, second dimension is used to store solution at time t span and third dimension for solution at time t
span and mesh points.