Lab Report 5
Lab Report 5
Name of the Experiment:MATLAB program for matrix operations, definite integration of a function and
Gauss elimination method.
Objectives:Objectives of this experiment are 1. To get familiar with different matrix operations such as- matrix addition, subtraction,
multiplication & division.
2. Finding out the value of the definite integral of a function and
3. Finding out the roots of simultaneous linear equations using Gauss elimination
method.
Theory:MATLAB is the precise form of Matrix Laboratory. From the name itself it is
easily understood that MATLAB performs matrix operations. All kind of matrix operations
can be performed through MATLAB. Value of the definite integral of any function can be
obtained by proper coding in MATLAB. Gauss elimination method has also been performed
in the laboratory. Brief description of all of these are given belowMatrix operation:We can represent a matrix in MATLAB as followingS=[ r1 ; r2 ; . ; rn]
Where r represents the row of a given matrix & the subscript 1, 2, . ,n represents the
number of row. r is expressed as followsr = a1, a2, . , an
Where a is the element of a particular row. An example of this form is given belowS=[ 1, 2, 3; 6, 5, 7; 10, 9, 8 ]
Here S is a 3*3 matrix whose elements are shown as described in above format.
Matrix arithmetic operations are done easily. For adding, subtracting, multiplying or dividing
two matrix we will have to just express those matrix as above format and then use the
required arithmetic operators between them such as + for addition, - for subtraction etc. The
arithmetic operations will be shown below in the MATLAB program section.
Definite integral of a function:We can find out the value of the definite integral of a function using quad. Quad is
the precise form of quadrature. Quadrature is a numerical method used to find the area under
the graph of a function, that is, to compute a definite integral. But for integrating a function
we will have to hanle it first using function handling symbol @(x) . After calling the function
properly we will have to use quad. Let the called function has been kept in k. Now quad is
used as followsintegral= quad( k, a, b)
Where a and b are the lower and upper limit of that function respectively.
An example of using these are given belowk= @(x) sin(x);
integral= quad( k, 0, pi )
Here the function sin(x) has been kept in k and 0 & pi have been taken as lower and upper
limit. In this way we can obtain the definite integral value of any function.
Gauss elimination method:Gauss elimination is one of the methods of solving simultaneous lineaer
equations. This method is also known as row reduction method. For solving a system of
linear equatios using Gauss elimination method we need to follow some steps. Fisrtly we
need to convert the system into an equivalent upper triangular system. Then we have to solve
it using back substitution method. This solution process is described belowLet the system of n linear equations with n unknowns be given bya11x1 + a12x2 + a13x3 + +a1nxn = b1
a21x1 + a22x2 + a23x3 + +a2nxn = b2
a31x1 + a32x2 + a33x3 + +a3nxn = b2
.
.
.
7 11
7 11
12 15
subtraction =
-1
1
-1
-1
1
0
-1
1
1
multiplication =
45
56
84
43 56
56 74
94 128
division =
0
1.0000
1.0000
0
-1.5000 2.0000
0
0
1.0000
pi=3.1416;
f=@(x) sin(x).^2.*cos(x);
i=quad(f,(-pi/2),(pi/2));
disp(' integrated value of the function is - ')
disp(i)
Output:integrated value of the function is 0.6667
Gauss elimination method:We will have to solve the following system using Gauss elimination method5x-2y+z = 4
7x+y-5z = 8
3x+7y+4z = 10
MATLAB program to solve this is given belowclc
clear all
a = [5 -2 1 4; 7 1 -5 8; 3 7 4 10];
[r c] = size(a);
for k= 1:(r-1)
for i = k:(r-1)
b = a(i+1,k)/a(k,k);
for j = 1:c
a(i+1,j) = a(i+1,j) - a(k,j)*b;
end
end
end
x=zeros(r,1);
a
x(r)= a(r,c)/a(r,r);
for i=r-1:-1:1
x(i)=(a(i,c)-a(i,i+1:r)*x(i+1:r))/a(i,i);
end
x'
Output:a=
0.8685
0.1407
Conclusion:The equations were written in the matrix form while performing Gauss
elimination method in MATLAB. Both the upper triangular form and the solutions had been
shown in output of Gauss elimination method which justified the theory described above.
The zeros function was used just to create a matrix of zeros at the beginning of the back
substitution. The concept of matrix arithmatic operation which had also been performed
before Gauss elimination method, had been utilized here. The definite integration can also
been performed using integral instead of quad , the rest procedure would be the same. We
can use any one between integral and quad.