0% found this document useful (0 votes)
77 views15 pages

Paper 6.1 LAB Manual

The document is a lab manual for a B.Sc. Mathematics course covering Python commands related to Rings, Integral Domains, Fields, Vector Spaces, Linear Transformations, and Calculus of Variations. It includes various labs with Python programs to verify properties of rings, perform vector operations, and solve variational problems. Each lab provides specific tasks, Python code examples, and expected outputs.

Uploaded by

viju.shanbhag94
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views15 pages

Paper 6.1 LAB Manual

The document is a lab manual for a B.Sc. Mathematics course covering Python commands related to Rings, Integral Domains, Fields, Vector Spaces, Linear Transformations, and Calculus of Variations. It includes various labs with Python programs to verify properties of rings, perform vector operations, and solve variational problems. Each lab provides specific tasks, Python code examples, and expected outputs.

Uploaded by

viju.shanbhag94
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

B.Sc.

, VI SEMESTER
(NEP-2020 Batch)
Python Commands for

MATHEMATICS
PAPER 6.1
LAB MANUAL
Topic:
Rings, Integral Domains, Fields
Vector Spaces,
Linear Transformation,
Calculus of Variations
Contents

Sl.No. Title
PART A: Ring Theory
Lab 1 Program to verify given ring is a commutative
ring or not.
Lab 2 Program to verify given ring with/without unity
or not
Lab 3 Program to verify given ring with/without zero
divisors
Part B: Vector spaces &
Linear Transformation
Lab 4 Program on Linear Combination of Vectors.
Lab 5 Program to verify Linear dependence and
independence.
Lab 6 Program to find basis and dimension of the
subspace.
Lab 7 Program to verify if a function is linear
transformation or not.
Lab 8 Lab 8: Program to find the matrix of linear
transformation.
Lab 9 Program to find the Eigenvalues of a given
linear transformation.
Part C: Calculus of Variations
Lab 10 Program to verify Variational problems using
Euler’s General formula.
Lab 11 Program to verify Variational problems using
particular forms of Euler’s equations
independent of both x and y
Lab 12 Program to verify Variational problems using
particular forms of Euler’s equations with
equations independent of y
PART A: Ring Theory
Lab 1:Program to verify given ring is a
commutative ring or not.
1) Verify the given ring (�, ⨁� , ⨂� ),
where G={0,1,2,3,4,5,6} is commutative or not.

Python command:

G={0,1,2,3,4,5,6}
def f(a,b):
return (a*b)%7
for a in G:
for b in G:
if f(a,b)!=f(b,a):
print("Ring is not commutative")
break
else:
print("Ring is commutative")

Output:
Ring is commutative

2) Verify the given ring (�, ⨁� , ⨂� ),


where G={0,1,2,3,4} is commutative or not.

3) Verify the given ring (�, ⨁�� , ⨂�� ),


where G={0,2,4,6,8} is commutative or not.
Lab 2:Program to verify given ring with/without
unity or not.

1) Verify the given ring (�, ⨁� , ⨂� ),


where G={0,1,2,3,4} is a ring with unity or not.

Python command:

G={0,1,2,3,4}
def f(a,b):
return (a*b)%5
for a in G:
k=0
for b in G:
if f(a,b)==b and f(b,a)==b:
e=a
k+=1
if k==len(G):
print(e,'is the multiplicative identity and the
ring is with unity')
break
else:
print('Multiplicative identity does not exists,
hence given ring is without unity')

Output:

1 is the multiplicative identity and the ring is with unity

2) Verify the given ring (�, ⨁� , ⨂� ),


where G={0,1,2,3,4,5,6} is a ring with unity or not.

3) Verify the given ring (�, ⨁�� , ⨂�� ),


where G={0,2,4,6,8} is a ring with unity or not.
Lab 3: Program to verify given ring with/without
zero divisors

1) Verify the given ring (�, ⨁� , ⨂� ),


where G={0,1,2,3,4,5} is a ring with or without zero divisors.

Python command:

G={0,1,2,3,4,5}
G=G.difference({0})
def f(a,b):
return (a*b)%6
k=1
for a in G:
for b in G:
if f(a,b)==0:
k=0
break
if k==0:
print("Ring is with zero divisors")
else:
print('Ring is ring without zero divisors')

Output:

Ring is with zero divisors

2) Verify the given ring (�, ⨁� , ⨂� ), where G={0,1,2,3,4} is a


ring with or without zero divisors.

3) Verify the given ring (�, ⨁�� , ⨂�� ),


where G={0,2,4,6,8} is a ring with or without zero divisors.
PART B: Vector spaces & Linear Transformation
Lab 4: Program on Linear Combination of Vectors.

1) Express the vector (1, 7, -4) as a linear combination of


vectors { (2, -1, 1), (1, -3, 2)}.

Python Command:
from sympy import *
var('a,b')
V=[1,7,-4]
V1=[2,-1,1]
V2=[1,-3,2]
A=Matrix([V1, V2, V]).T
soln=solve_linear_system(A,a,b)
if soln==None:
print("Given vector V cannot be expressed as a linear
combination of V1 and V2")
else:
print("Given vector V can be expressed as a linear
combination of V1 and V2")
print("Scalars are: \n", soln)

Output:
Given vector V can be expressed as a linear combination
of V1 and V2
Scalars are:
{a: 2, b: -3}

2) Express (3, 7, -4) as a linear combination of the vectors


(1, 2, 3), (2, 3, 7), (3, 5, 6) if possible.

3) Express (2, -5, 3) as a linear combination of vectors


{ (1, -3, 2), (2, -4, -1), (1, -5, 7) } if possible.

4) Express (3, -7, 6) as a linear combination of vectors


{ (1, -3, 2), (2, 4, 1), (1, 1, 1) } if possible.
Lab 5: Program to verify Linear dependence and independence.

1) Examine whether the set of the vectors


{ (1, 3, 2), (1, -7, -8), (2, 1, -1) } linearly independent or not.

Python Command:
from sympy import *
V1=[1,3,2]
V2=[1,-7,-8]
V3=[2,1,-1]
A=Matrix([V1, V2, V3])
D=det(A)
print("Determinant=",D)
if D!=0:
print("Given vectors are linearly independent")
else:
print("Given vectors are linearly dependent")

Output:
Determinant= 0
Given vectors are linearly dependent

2) Examine whether the set of the vectors


{ (1, 1, -1), (2, -3, 5), (-2, 1, 4) } linearly independent or not.

3) Examine whether the set of the vectors


{ (6, 0, -1), (1, 1, 4), (-2, 1, 4) } linearly independent or not.

4) Examine whether the set of the vectors


{ (1, 2, 3), (3, 1, 0), (-2, 1, 3) } linearly independent or not.
Lab 6: Program to find basis and dimension of the subspace.

1) Verify whether the set of vectors


(1, 1, -1), (2, -3, 5), (2, -1, 4) form basis or not.

Python Command:
from sympy import *
V1=[1,1,-1]
V2=[2,-3,5]
V3=[2,-1,4]
A=Matrix([V1, V2, V3])
D=det(A)
print("Determinant=",D)
if D!=0:
print("Given vector form a basis of R^3")
else:
print("Given vector does not form a basis of R^3")

Output:
Determinant= -9
Given vector form a basis of R^3

2) Verify whether the set of vectors


(1, 1, 0), (0, 1, 0), (0, 1, 1) form basis of R3.

3) Find the basis and dimension of the subspace spanned


by the set of vector B={ (1, 2, 3), (3, 1, 0), (-2, 1, 3) }.

4) Find the basis and dimension of the subspace spanned


by the set of vector { (1, 1, 1), (1, 2, 3), (-1, 0, 1) } of R3.
Lab 7: Program to verify if a function is linear
transformation or not.

1) Verify whether T:V2(R)→V2(R) defined by T(x,y)=(x+y, y)


is a linear transformation or not.

Python Command:
from sympy import *
from operator import add
var('x,y')
var('x1,y1,x2,y2,c')
T=lambda x: [x[0]+x[1],x[1]]
X=[x,y]
print("Given transformation T(x,y)=",T(X))
X=[x1,y1]
Y=[x2,y2]
L1=T(list(map(add,X,Y)))
R1=list(map(add,T(X),T(Y)))
L2=T(list(map(lambda x: c*x,X)))
R2=list(map(lambda x: expand(c*x),T(X)))
if L1==R1 and L2==R2:
print("T is linear Transformation")
else:
print("T is not linear Transformation")

Output:
Given transformation T(x,y)= [x + y, y]
T is linear Transformation

2) Verify whether T:V3(R)→V2(R) defined by


T(x,y,z)=(x+y, y+z) is a linear transformation or not.

3) Verify whether T:V3(R)→V3(R) defined by


T(x,y,z)=(0, y, z) is a linear transformation or not.

4) Verify whether T:V2(R)→V2(R) defined by


T(x,y)=(xy, x) is a linear transformation or not.
Lab 8: Program to find the matrix of linear transformation.

1) Find the matrix of Linear Transformation T:R2→R2


defined by T(x, y)=(2x+3y, 4x-5y) w.r.t standard basis.

Python Command:

from sympy import *


var('x,y,a,b')
T=lambda x: [2*x[0]+3*x[1],4*x[0]-5*x[1]]
X=[x,y]
print("Given transformation T(x,y)=",T(X))
U1=[1,0];U2=[0,1];V1=[1,0];V2=[0,1]
B1=[U1,U2];B2=[V1,V2]
m=n=2
A=zeros(n,m)
for i in range (0,m):
eq=Matrix([V1,V2,T(B1[i])]).T
soln=solve_linear_system(eq,a,b)
A[:,i]=Matrix([soln[a],soln[b]])
print("\n Associated matrix of LT:")
pprint(A)

Output:
Given transformation T(x,y)= [2*x + 3*y, 4*x - 5*y]
Associated matrix of LT:
⎡ 2 3⎤
⎢ ⎥
⎣ 4 -5 ⎦

2) Find the matrix of Linear Transformation T:V3(R)→V2(R)


defined by T(x, y, z)=(x+y, y+z) relative to basis
B1={(1, 1, 1), (1, 0, 0), (1, 1, 0)} and B2={C1, C2}.

3) Find the matrix of Linear Transformation T:V2(R)→V3(R)


defined by T(x, y)=(2y-x, y, 3y-3x) relative to the basis
B1={(1, 1), (-1, 1)} and B2={(1, 1, 1), (1, -1, 1), (0, 0, 1)} .
Lab 9: Program to find the Eigen values of a given linear
transformation.

1) Find the Eigen values of the matrix of the Linear


� �
Transformation � =
� �

Python Command:

from sympy import *


import numpy as np
import sympy as sy
from numpy.linalg import eig
sy.init_printing()
lamda=sy.symbols('lamda')
A=np.array([[1,2],[3,2]]).astype(float);A
I=sy.eye(2)
Z=A-lamda*I
pprint(Z)
y=np.linalg.eigvals(A)
print('Eigen values',y)

Output:
⎡ 1.0 - λ 2.0 ⎤
⎢ ⎥
⎣ 3.0 2.0 - λ⎦
Eigen values [-1. 4.]

2) Let T : R2→R2 be defined by T(1, 0)= (1, 2); T(0, 1)=(4, 3).
Find the Eigen values of the linear Transformation.

3) Find the Eigen values of the Linear Transformation


T : R3→R3 defined by T(x,y,z) = (x+y+z, 2y+z, 2y+3z).

4) Find the Eigen values of the Linear Transformation


T : V3(R)→V3(R) defined by T(x,y,z) = (2x+2y+z, x+3y+z,
x+2y+2z).
PART C: Calculus of Variation

Lab 10: Program to verify Variational problems using


Euler’s General formula.

 
1
1) Solve the Variational problem I    y'   xy dx
2

0
with y(0)=0 and y(1)=0.
Python Command:
from sympy import *
x=symbols('x')
f=Function('f')
y=Function('y')
f=lambda y,x:diff(y(x),x)**2+x*y(x)
eq=diff(f(y,x),y(x))-diff(diff(f(y,x),diff(y(x),x)),x)
soln=dsolve(eq,ics={y(0):0,y(1):0})
pprint(soln)

Output:
x3 x
y( x )  
12 12
 
1
2) Solve the Variational problem I   12 xy   y'  dx
2

0
with y(0)=0 and y(1)=1.

3) Find the extremal of the functional

 
/2
I   y 2   y'   2 y sin x dx
2

0
with the condition y(0)=0 and y(�/�)=0.

4) Find the extremal of the functional

 
x2
I   y 2   y'   2 ye x dx .
2

x1
Lab 11: Program to verify Variational problems using
particular forms of Euler’s equations independent of both
x and y

1) Find the extremal of the functional I


1

0
  y'   1dx
2
,

with y(0)=1 and y(1)=2.


Python Command:

from sympy import *


x=symbols('x')
y,f=symbols('y,f',cls=Function)
f=lambda y,x:sqrt(diff(y(x),x)**2+1)
eq=diff(f(y,x),y(x))-diff(diff(f(y,x),diff(y(x),x)),x)
soln=dsolve(eq,ics={y(0):1,y(1):2})
pprint(soln)

Output :

y(x) = x + 1
1  dy  2 dy 
2) Solve the Variational problem I       1 dx ,
0 dx  dx 
with y(0)=1 and y(1)=3.

3) Find the extremal of the functional


2
 
I   4 y'   3 dx ,
0
2

with y(0)=2 and y(2)=4.

4) Find the curve passing through (0,0) and (�, �) along

 

I    y'  dx .
2
which
0
Lab 12: Program to verify Variational problems using
particular forms of Euler’s equations with equations
independent of y

 
x2
I   y ' x 2  y'  dx .
2
1) Find the extremal of the functional
x1
Python Command:

from sympy import *


var('k,x')
y,f=symbols('y,f',cls=Function)
f=lambda y,x:diff(y(x),x)+x**2*diff(y(x),x)**2
eq=diff(f(y,x),diff(y(x),x))-k
soln=dsolve(eq)
pprint(soln)

Output:
k 1
y( x )  c1 
2x
 
4
I   xy ' y'  dx ,
2
2) Find the extremal of the functional
0
with y(0)=0 and y(4)=3.

Python Command:

from sympy import *


x=symbols('x')
y,f=symbols('y,f',cls=Function)
f=lambda y,x:x*diff(y(x),x)+diff(y(x),x)**2
eq=diff(f(y,x),y(x))-diff(diff(f(y,x),diff(y(x),x)),x)
soln=dsolve(eq,ics={y(0):0,y(4):3})
pprint(soln)

Output:
x2 7x
y( x )   
4 4
 
2
3) Find the extremal of the functional I   3 x  y' dx ,
1
with y(1)=5 and y(2)=7.

 
1
I   xy ' y'  dx ,
2
4) Solve the Variational problem
0
with y(0)=1 and y(1)=1/4.

You might also like