TRIBHUVAN UNIVERSITY
PRITHVI NARAYAN CAMPUS
Pokhara-1, Kaski
Lab Report on
Lab report on Matlab
Submitted To:
Bhadra Raj Tripathi
Lecturer
Department of Mathematics
Submitted By:
Kisagar Subedi
First semester
Roll no:29
Shrawn,2079
Practical No: 1
Title:
Construction of matrices and their operations.
Objective:
i) To create matrices and perform their addition,
subtraction and multiplication.
ii) To find determinant, inverse, rank and adjoint of
matrices.
Program 1. i : 3 x 3 matrix and perform the operation of addition,
subtraction and multiplication.
Syntax :
A = [1 2 3 ;4 5 6;7 8 9] and B = [4 5 6; 6 7 8; 9 10 11]
Execute:
i) A+B , ii) A-B , iii) AB or BA,
Input
A = [1 2 3 ;4 5 6;7 8 9]
A=
1 2 3
4 5 6
7 8 9
>> B = [4 5 6; 6 7 8; 9 10 11]
B=
4 5 6
6 7 8
9 10 11
Output:
>> A+B
ans =
5 7 9
10 12 14
16 18 20
>> A-B
ans =
-3 -3 -3
-2 -2 -2
-2 -2 -2
>> A*B
ans =
43 49 55
100 115 130
157 181 205
ii) To perform the following operations.
i)det(A) ii) inv(A) rank(A) iv) adjoint of A
Syntax :
A = [1 2 3 ;4 5 6;7 8 9] and B = [4 5 6; 6 7 8; 9 10 11]
Execute:
i)det(A) ii) inv(A)iii) rank(A) iv) adjoint of A ( det(A) *inv(A))
Input:
A = [1 2 3 ;4 5 6;7 8 9]
A=
1 2 3
4 5 6
7 8 9
>> B = [4 5 6; 6 7 8; 9 10 11]
B=
4 5 6
6 7 8
9 10 11
Output:
det(A)
ans =
0
inv(A)
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.541976e-018.
ans =
1.0e+016 *
-0.4504 0.9007 -0.4504
0.9007 -1.8014 0.9007
-0.4504 0.9007 -0.4504
rank(A)
ans =
2
det(A) *inv(A)
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.541976e-018.
ans =
0 0 0
0 0 0
0 0 0
Discussion:
By using matlab , I performed addition, subtraction and
multiplication of 3x3 matrices and calculated determinant, rank etc.
Similarly, I can perform 2x2 ,4x4 matrices using arithmetic operation.
Signature: …………….
Subject Teacher
Date:………………….
Practical No: 2
Title:
Solution system of linear equations.
Objective:
To solve system of linear equations.
Program 2: Solving System of Linear Equation.
x+2y+4z=3, 2x+3y+4y=9 and 2x-y+3z=3
Syntax:
A=[1 2 4; 2 3 4;2 -1 3]
B=[3; 9; 3]
AX=B
Execute:
X= inv(A)*B
Input:
A=[1 2 4; 2 3 4;2 -1 3]
A=
1 2 4
2 3 4
2 -1 3
>> B=[3; 9; 3]
B=
3
9
3
Output:
>> inv(A)*B
ans =
4.2000
1.8000
-1.2000
Discussion:
By using matlab, we performed system of linear equation
with inputs A and B , obtained output X. Similarly , we can perform other
solving system of linear equations.
Signature: …………….
Subject Teacher
Date:………………….
Practical No: 3
Title:
Solution of Algebraic Equations.
Objective:
i)To create Algebric Equation of x + 4=0.
ii)To create Algebric Equation of x^3 + x^2 - 8x - 8=0.
Program 3.i: Solving Algebraic Equation.
i) x + 4=0
Syntax:
equation =[1 4];
roots(equation)
Output:
ans =
-4
Program [Link]: Solving Algebraic Equation.
ii) x^3 + x^2- 8x-8=0
Syntax:
equation =[1 1 -8 -8];
roots(equation)
Output:
ans =
2.8284
-2.8284
Discussion:
By using matlab, we performed the solution of algebraic
equation. Similarly, we can solve other algebraic equations.
Signature: …………….
Subject Teacher
Date:………………….
Practical No: 4
Title:
Construction of Graph.
Objective:
i) To construct a graph of line Y=x^2.
ii) To construct a graph of y = sin x and g = cos x.
iii) To construct a graph of f(x) = 3x4 + 2x3+ 7x2 + 2x +
5 and g(x) = 5x3 + 9x + 4.
Program 4 .i: Draw a line of y =x2.
Syntax:
x = [1 2 3 4 5 6 7 8 9 10];
x = [-[Link];
y = x.^2;
plot(x, y)
Output:
Program 4 . ii Draw the graph of y = sin x and g = cos x.
Syntax:
x = [0 : 0.01: 10]; y = sin(x);
g = cos(x);
plot(x, y, x, g, '.-'),
legend('Sin(x)', 'Cos(x)')
Output:
Program 4 .iii: Draw the graph of f(x) = 3x4 + 2x3+ 7x2 + 2x + 5
and g(x) = 5x3 + 9x + 4.
Syntax:
x = [-10 : 0.01: 10];
y = 3*x.^4 + 2 * x.^3 + 7 * x.^2 + 2 * x + 5;
g = 5 * x.^3 + 9 * x + 4;
plot(x, y, 'r', x, g, 'g')
Output:
Discussion:
By using matlab ,we performed construction of
graph of line Y=X^2 , Y= Sin X and G=Cos X and f(x) = 3x4 + 2x3+
7x2 + 2x + 5 and g(x) = 5x3 + 9x + 4. Similarly , we can perform
construction of a graph with other line such as: Y=X, Y=X^3 ,
Y=X^4 and so on.
Signature: …………….
Practical No: 5
Title:
Construction of circle with different radii.
Objective:
i) To construct a circle of equation: x2 + y2 = r2.
ii) To construct a circle of equation: (x – h)2 + (y – k)2
= r2 .
Program 5:i) Draw the circle; x2 + y2 = r2.
Syntax:
r = 12;
theta = 0:0.1:2*pi
x = r* cos(theta);
y = r* sin(theta);
plot(x, y)
Output:
Program 5:ii) Draw the circle; (x – h)2 + (y – k)2 = r2
Syntax:
r = 12; h = 4;
k = 5;
theta = 0:0.1:2*pi;
x = r* cos(theta) + h;
y = r* sin(theta) + k;
plot(x, y,':r*');
title('Circle');
xlavel('x-axis');
yaxis('y-axis');
legend('Graph of Circle')
Output:
Discussion:
By using matlab, we performed construction of
circle with center equal to '0' and center (h, k)= (4 , 5)and radius
(r) 12. Similarly, we can perform construction of other circle
with different radii and center.
Signature: …………….
Subject Teacher
Date:………………….
Practical No: 6
Title:
Construction of space curve.
Objective:
i) To construct a space curve : z = x3 – 5xy3 ,
where |x|≤ 5 and |y|≤ 5.
ii) To construct a space curve: x = r cos , y = r
sin, z = where 0 ≤ ≤ 4π and r = 12.
Program 6: i) Plot the space Curve; z = x3 – 5xy3 , where |x|≤ 5
and |y|≤ 5.
Syntax:
x = -5:0.5:5;
y = -5:0.5:5;
z = x.^3 - 5*x.* y.^2;
plot3(x,y,z)
Output:
Program 6:ii) Plot the space Curve; x = r cos , y = r sin, z =
where 0 ≤ ≤ 4π and r = 12.
Syntax:
r = 12;
theta = 0: 0.5: 4*pi;
x = r* cos (theta);
y = r* sin (theta);
z = (theta);
plot3(x,y,z)
z = sin(x) + sin(y)
surf(x, y, z)
Output:
Discussion:
By using matlab we performed the drawing space
curve of z = x3 – 5xy3 and : x = r cos , y = r sin, z = .Similarly,
we can draw other space curve same as above operation.
Practical No: 7
Title:
Construction of 3D graphs.
Objective:
i) To construct 3D graph: z = x2 + y2 where -6 ≤
x, y ≤ 6.
ii) To construct 3D graph: z = sin x + cos x
contour where -12 ≤ x, y ≤ 12.
iii) To construct contour graph : x2 + y2
Program 7: i) Plot the 3D graphs of z = x2 + y2 where -6 ≤ x, y ≤
6.
Syntax:
x = -6:0.1:6;
y=x;
[x, y] = meshgrid(x, y);
z = x.^2 + y.^2;
surf(x, y, z)
Output:
Program 7: ii) Plot the 3D graphs of z = sin x + cos x contour
where -12 ≤ x, y ≤ 12.
Syntax:
x = -10:0.1:10;
y=x;
[x, y] = meshgrid(x, y);
z = sin(x) + sin(y)
surfc(x, y, z)
Output:
Program 7:iii) Draw the contour of the function x2 + y2.
Syntax:
[x,y] = meshgrid(-5:0.1:5,-3:0.1:3);
g = x.^2 + y.^2
contour(x,y,g)
Print -deps [Link]
Output:
Discussion:
By using, matlab we plot 3D graphs of contour
equation z = x2 + y2 where -6 ≤ x, y ≤ 6 , z = sin x + cos x
contour where -12 ≤ x, y ≤ 12 and . Similarly, we can plot other
3D graphs of contour same as above operation.
Signature: …………….
Subject Teacher
Date:
………………….
Practical No:8
Title:
Construction of Vectors and their operation.
Objective:
i)To create vector and their length, dot product and
cross product.
ii) To create scalar triproduct and vector product.
Program 8: i) Find the length of vector ❑
⃗ a=(3 , 4 , 6)
Syntax:
V = [3 4 6];
norm(V)
Output:
ans =
7.8102
Program 8: ii) Find dot product and cross product of vector I
⃗ A=[2 , 4 ,5] and ❑
❑ ⃗ B=[5 , 4 , 7] using matlab .
Syntax:
A=[2 , 4 , 5];
B=[5 , 4 , 7] ;
dot(A,B)
cross(A,B)
Output:
dot(A,B)
ans =
61
cross(A,B)
ans =
8 11 -12
Program 8: iii) Find triproduct and vector product of vector I
⃗ A=[2 , 4 ,5] and ❑
❑ C=¿[7 , 5 , 8]¿ using matlab .
⃗ B=[5 , 4 , 7] ⃗
Syntax:
A¿ [2 4 5 ];
B=[5 4 7];
C=[7 5 8] ;
dot (A,cross(B,C))
cross(A,cross(B,C))
Output:
daddzzzzzzzz
dot (A,cross(B,C))
ans =
15
cross(A,cross(B,C))
ans =
-57 -9 30
- Note:
- i) dot (A,cross(B,C)) [scalar triple product of a,b, c ⃗ ¿ ¿]
- ii) cross(A,cross(B,C)) [ vector product of a, b, c ⃗
¿ ¿]
-
Discussion:
By using matlab , we performed various operation of vector
such as length, dot product, cross product, scalar triple product and
vector product. Similarly, we can perform other operation same as
above.
Signature: …………….
Subject Teacher
Date:………………….