Matlab Report Isem
Matlab Report Isem
Lab Report on
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.
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.
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 *
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:
Signature: …………….
Subject Teacher
Date:………………….
Practical No: 2
Title:
Solution system of linear equations.
Objective:
To solve system of linear equations.
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:
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:
Output:
ans =
-4
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.
Syntax:
x = [1 2 3 4 5 6 7 8 9 10];
x = [-100:10:100];
y = x.^2;
plot(x, y)
Output:
Syntax:
g = cos(x);
plot(x, y, x, g, '.-'),
legend('Sin(x)', 'Cos(x)')
Output:
Syntax:
x = [-10 : 0.01: 10];
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:
Syntax:
r = 12;
theta = 0:0.1:2*pi
x = r* cos(theta);
y = r* sin(theta);
plot(x, y)
Output:
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.
Syntax:
x = -5:0.5:5;
y = -5:0.5:5;
z = x.^3 - 5*x.* y.^2;
plot3(x,y,z)
Output:
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:
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
Syntax:
x = -6:0.1:6;
y=x;
[x, y] = meshgrid(x, y);
z = x.^2 + y.^2;
surf(x, y, z)
Output:
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)
Output:
Discussion:
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.
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:………………….