Practical File: Mathematics For Computing
Practical File: Mathematics For Computing
Practical File: Mathematics For Computing
File
Mathematics
for
Computing
SOUMYA TRIPATHI
Course: B.Sc(hons)Computer
Science
Roll Number:23HCS4177
SOUMYA TRIPATHI
Course: B.Sc(hons)Computer Science
Roll Number:23HCS4177
pg. 0 SOUMYA TRIPATHI
Course: B.Sc(hons)Computer Science
Roll Number:23HCS4177
Ques.1.
Find cofactors, determinant, adjoint and inverse
of a matrix.
Codes and Output:
a: matrix (
[1,2],
[2,3]
);
1 2
( )
2 3
determinant(a);
−1
adjoint(a);
3 −2
( )
−2 1
transpose(a);
1 2
( )
2 3
invert(a);
−3 2
( )
2 −1
cofactor:(transpose(adjoint(a)));
3 −2
( )
−2 1
SOUMYA TRIPATHI
Course: B.Sc(hons)Computer Science
Roll Number:23HCS4177
Ques.2.
Convert the matrix into echelon form and find its
rank.
Codes and Output:
A: matrix(
[2,-1,2],
[-1,2,-1],
[1,-1,2]
);
echelon(A);
1
1 −( ) 1
( 2 )
0 1 0
0 0 1
rank(A);
3
SOUMYA TRIPATHI
Course: B.Sc(hons)Computer Science
Roll Number:23HCS4177
Ques.3.
Solve a system of equations using Gauss
elimination method.
Code:
[AugU],
AugU:echelon(addcol(A,b)),
backsolve(AugU)
);
backsolve(augU):=block(
[i,j,m,n,b,x,klist,k,np,nosoln:false],
[m,n]:matsize(augU),
b:col(augU,n),
klist:makelist(concat('%k,i),i,1,n-1),
k:0,
x:transpose(matrix(klist)),
for i:m thru 1 step -1 do (
np:pivot(row(augU,i)),
if is(equal(np,n)) then
(nosoln:true,return())
else if not(is(equal(np,0))) then
(x[np]:b[i],
for j:np+1 thru n-1 do
x[np]:x[np]-augU[i,j]*x[j])
),
if nosoln then
return([])
else
return(expand(x))
)$
matsize(A):=[length(A),length(transpose(A))]$
pivot(rr):=block([i,rlen],
p:0,
rlen:length(transpose(rr)),
for i:1 thru rlen do(
if is(equal(part(rr,1,i),1)) then (p:i,return())),
return(p)
)$
matsolve(A,b);
Output:
matsolve(𝐴, 𝑏)
≔ block([𝐴𝑢𝑔𝑈], 𝐴𝑢𝑔𝑈: echelon(addcol(𝐴, 𝑏)) , backsolve(𝐴𝑢𝑔𝑈))
SOUMYA TRIPATHI
Course: B.Sc(hons)Computer Science
Roll Number:23HCS4177
43
12
41
24
(−2)
Ques.4.
Solve a system of linear equations using Gauss
Jordan method.
Code:
load(mbe5);
A:matrix([8,5,1],[3,6,4],[9,7,2]);
b:[2,1,0];
x:[x,y,z];
gauss_jordan(A,b,x);
Output:
SOUMYA TRIPATHI
Course: B.Sc(hons)Computer Science
Roll Number:23HCS4177
Ques.5.
Verify the dependence of vectors. Generate a
linear combination of given vectors Rn/ matrices
of the same size.
Code and Output:
a: matrix(
[1,2]
);
(1 2)
b: matrix(
[3,4]
);
(3 4)
z:3*a+4*b;
(15 22)
SOUMYA TRIPATHI
Course: B.Sc(hons)Computer Science
Roll Number:23HCS4177
Ques.6.
Check the diagonalizable property of matrices and
find the corresponding eigenvalue and verify the
Cayley Hamilton Theorem.
Code and Output:
load(mbe5)
A: matrix(
[2,-1,2],
[-1,2,-1],
[1,-1,2]
);
2 −1 2
(−1 2 −1)
1 −1 2
charpoly(A,lambda);
𝜆 + 2(𝜆 − 1) + ((2 − 𝜆)2 − 1)(2 − 𝜆) − 1
c:charpoly(A,lambda);
𝜆 + 2(𝜆 − 1) + ((2 − 𝜆)2 − 1)(2 − 𝜆) − 1
expand(c);
−𝜆3 + 6𝜆2 − 8𝜆 + 3
R:-(A^^3)+6*(A^^2)-8*A+3*ident(3);
0 0 0
(0 0 0)
0 0 0
SOUMYA TRIPATHI
Course: B.Sc(hons)Computer Science
Roll Number:23HCS4177
mat:matrix([0,0,0],[0,0,0],[0,0,0]);
0 0 0
(0 0 0)
0 0 0
is(equal(R,mat));
𝑡𝑟𝑢𝑒
SOUMYA TRIPATHI
Course: B.Sc(hons)Computer Science
Roll Number:23HCS4177
Ques.7.
Compute gradient of a scalar field and Divergence
and Curl of a vector field.
load(vect);
[𝑧 2 , 𝑦 2 , 𝑥 2 ]
curl(F);
curl([𝑧 2 , 𝑦 2 , 𝑥 2 ])
express(curl(F));
𝑑 𝑑 𝑑 𝑑 2 𝑑 2 𝑑 2
[ 𝑥2 − 𝑦2, 𝑧2 − 𝑥 , 𝑦 − 𝑧 ]
𝑑𝑦 𝑑𝑧 𝑑𝑧 𝑑𝑥 𝑑𝑥 𝑑𝑦
ev(express(curl(F)),diff;
[0,2𝑧 − 2𝑥, 0]
For computation of Gradient
f(x,y,z):=2*y^3+4*x*z+3*x;
𝑓(𝑥, 𝑦, 𝑧) ≔ 2𝑦 3 + 4𝑥𝑧 + 3𝑥
g:grad(f(x,y,z));
grad(4𝑥𝑧 + 2𝑦 3 + 3𝑥)
ev(express(g),diff);
F:[3*x*z,2*x*y,-y*z^2];
SOUMYA TRIPATHI
Course: B.Sc(hons)Computer Science
Roll Number:23HCS4177
ev(express(div(F)),diff);
−(2𝑦𝑧) + 3𝑧 + 2𝑥
SOUMYA TRIPATHI
Course: B.Sc(hons)Computer Science
Roll Number:23HCS4177