Matlab Manual 1st Sem (24-25) - OEE
Matlab Manual 1st Sem (24-25) - OEE
Prepared by:
Department of Mathematics
Vidyavardhaka College of Engineering
Mysuru
Task 1
Task 2
Consider the following system of linear equations:
2 x+ y−z=5 , 3 x + 4 y + z=−2
Create the coefficient matrix A for the system.
Create the constant vector b.
Find the determinant of A.
Find a solution to the system of equations using the backslash operator.
Task 4
Solve System of Linear Equations Using solve
Consider the following system of linear equations:
2 x+ y+ z =2
−x + y−z=3
x +2 y+ 3 z=−10
Declare the system of equations.
syms x y z
eqn1 = 2*x + y + z == 2;
eqn2 = -x + y - z == 3;
eqn3 = x + 2*y + 3*z == -10;
Solve the system of equations using solve.
sol = solve([eqn1, eqn2, eqn3], [x, y, z]);
xSol = sol.x
ySol = sol.y
zSol = sol.z
( )
3 2 1
A. Find the inverse of a matrix 0 1 0 using rref
1 2 0
>> R=rref([A eye(size(A))])
R=
1 0 0 0 -2 1
0 1 0 0 1 0
0 0 1 1 4 -3
>> inv_A = R(:,4:end)
B. Verify the above by finding the inverse of A using the inv function
>> inv(A)
ans =
0 -2 1
0 1 0
1 4 -3
*********
If a , b ∈ Z , b>0 , then there exist unique q ,r ∈ Z such that a=qb+ r ,0 ≤ r <b . Here q is called
quotient of the integer division of a by b , and r is called remainder.
MATLAB CODE:
a1=input('enter the first number\n');
b1=input('enter the second number\n');
a=a1;
b=b1;
i=1;
r(i)=rem(a,b);
if r(i)==0
fprintf('GCD of %d and %d is : %d\n',a1,b1,b)
else
while(r(i)~=0)
a=b;
b=r(i);
i=i+1;
r(i)=rem(a,b);
end
fprintf('GCD of %d and %d is : %d\n',a1,b1,r(i-1))
end
OUTPUT
GCD_Euclidalgorithm
enter the first number
4578
enter the second number
50789
GCD of 4578 and 50789 is : 1
Linear congruence
Let d=(a ,m), and consider the equation ax ≡b (mod m).
(a) If d 6 | b, there are no solutions.
(b) If d | b, there are exactly d distinct solutions mod m.
MATLAB CODE
%Linear congruence
OUTPUT
linearcongruences
enter integer a
35
enter integer b
47
enter integer m
7
the congruence has no integer solution
*******
MATLAB Code
Problem 01
********