Kakade Practical
Kakade Practical
Practical No : 1
1)
> print('gorakshanath') gorakshanath
2)
> x=int(input('enter the value 1 = '));y=int(input('enter the value 2 ='));print(x+y) enter the value 1 = 23
enter the value 2
=20 43
3)
> from math import sin,cos;sin(3.6);cos(4.6) -0.44252044329485246 -0.11215252693505487
4)
a)
> 10>11
False
b)
> 13==13
True
5)
> from math import sin,cos;sin(8.4)+cos(10.5) 0.37906198009228803
Name:- kakade gorakshanath sandip
Class :- S.Y.B.Sc. (computer science)
Roll no:- 22
Practical No : 2
1)
> s='He is good in python'
> print(s)
He is good in python
2)
> l='hello python'
> print(len(l))
12
3)
> a='Ram is toper in class'
> b=' also ram play football'
> print(a+b)
Ram is toper in class also ram play football
4)
>>> l=[1,2,3,4,5]
> print('first element',l[0]); print('last element',l[4]) first element 1
last element 5
5)
> tuple=(44,55,66,13,23,56)
> print(sorted(list(tuple))) [13, 23, 44, 55, 56, 66]
Name:- kakade gorakshanath sandip
Class :- S.Y.B.Sc. (computer science)
Roll no:- 22
Practical No : 3
1)
> x=5
> if x<10:
... print('number is less than 10')
...
number is less than 10
2)
>>> if x%5==0:
... print('x is divisible by 5')
... else:
... print('x is not divisible by 5')
...
x is divisible by 5
4)
> x=3
> if x%2==0:
...print('even')
... else:
... print('odd')
...
odd
5)
> x=56
> if x>75:
... print('first class')
... elif x>60 and x<75:
... print('second')
... elif x>35 and x<60:
... print('pass')
... else:
... print('fail')
...
Pass
5)
> x=23
> y=35
> z=13
> if x>y and x>z:
... print('x is greater')
... elif y>x and y>z:
... print('y is greater')
... else:
... print('z is greater')
...
y is greater
Name:- kakade gorakshanath sandip
Class :- S.Y.B.Sc. (computer science)
Roll no:- 22
Practical No : 4
1)
> for n in range(1,20,1):
...if(n%2==0):
...print(n)
...
2
4
6
8
10
12
14
16
18
20
2)
>>>for n in range(1,20,2):
... print(n)
1
3
5
7
9
11
13
15
17
19
4)
> from sympy import*
> b=Matrix([[1,2,0],[0,3,0],[2,-4,2]])
> b.is_diagonalizable()
True
5)
> from sympy import*
> z=Matrix([[0,1],[0,0]])
> z.is_diagonalizable() False
Name:- kakade gorakshanath sandip
Class :- S.Y.B.Sc. (computer science)
Roll no:- 22
Practical No : 5
1)
a)
> from sympy import *
> a=Matrix([[1,2,3],[4,5,6],[7,8,9]])
> b=Matrix([[4,6,-3],[-4,1,6],[0,8,-9]])
> a+b
Matrix([
[5, 8, 0],
[0, 6, 12],
[7, 16, 0]])
b)
> from sympy import *
> a=Matrix([[1,2,3],[4,5,6],[7,8,9]])
> b=Matrix([[4,6,-3],[-4,1,6],[0,8,-9]])
> a-b
Matrix([
[-3, -4, 6],
[ 8, 4, 0],
[ 7, 0, 18]])
c)
> from sympy import *
> a=Matrix([[1,2,3],[4,5,6],[7,8,9]])
> b=Matrix([[4,6,-3],[-4,1,6],[0,8,-9]])
> a*b
Matrix([
[-4, 32, -18],
[-4, 77, -36],
[-4, 122, -54]])
2)
a)
> from sympy import *
> a=Matrix([[4,2,4],[4,-1,1],[2,4,2]])
> b=Matrix([[5,2,3],[3,-7,5],[3,1,-1]])
> a**3
Matrix([
[268, 146, 202],
[142, 83, 103],
[176, 112, 152]])
b)
> from sympy import *
> a=Matrix([[4,2,4],[4,-1,1],[2,4,2]])
> b=Matrix([[5,2,3],[3,-7,5],[3,1,-1]])
> b.inv()
Matrix([
[ 1/59, 5/118, 31/118],
[ 9/59, -7/59, -8/59],
[12/59, 1/118, -41/118]]
3)
a)
> from sympy import *
> eye(5)
Matrix([
[1, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 0],
[0, 0, 0, 0, 1]])
b)
> ones(4,3)
Matrix([ [1,
1, 1], [1, 1,
1], [1, 1, 1],
[1, 1, 1]])
> zeros(4,4)
Matrix([ [0,
0, 0, 0], [0,
0, 0, 0], [0,
0, 0, 0], [0,
0, 0, 0]])
4)
a)
b)
c)
d)
Practical No : 6
1)
a)
> from sympy import *
> a=Matrix([[4,6,-3],[-4,1,6],[0,8,9]])
> a.T
Matrix([ [ 4, -4, 0],
[ 6, 1, 8],
[-3, 6, 9]])
B)
> a.det()
156
2)
a)
> from sympy import *
> a=Matrix([[1,2,3],[4,5,6],[7,8,9]])
> a.rank()
2
b)
> from sympy import *
> a=Matrix([[1,2,3],[4,5,6],[7,8,9]])
> a.nullspace()
[Matrix([
[ 1],
[-2],
[ 1]])]
c)
> from sympy import *
> a=Matrix([[1,2,3],[4,5,6],[7,8,9]])
> a.columnspace()
[Matrix([
[1],
[4],
[7]]), Matrix([
[2],
[5],
[8]])]
3)
> from sympy import *
> a=Matrix([[4,6,-3],[-4,1,6],[0,8,-9]])
> a.rref()
(Matrix([
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]), (0, 1, 2))
Name:- kakade gorakshanath sandip
Class :- S.Y.B.Sc. (computer science)
Roll no:- 22
Practical No : 7
1)
> from sympy import *
> x,y,z=symbols("x,y,z")
> a=Matrix([[3,2,-1],[2,-2,4],[2,-1,2]])
> b=Matrix([3,6,9])
> linsolve((a,b),[x,y,z])
{(6, -11, -7)}
2)
> from sympy import *
> x,y,z=symbols("x,y,z")
> a=Matrix([[6,4,-2],[4,-6,8],[7,-1,2]])
> b=Matrix([8,5,8])
> linsolve((a,b),[x,y,z])
{(49/46, 33/46, 29/46)}
3)
> from sympy import *
> a=Matrix([[2,1],[1,2]])
> b=Matrix([5,7])
> a.gauss_jordan_solve(b) (Matrix([
[1],
[3]]), Matrix(0, 1, []))
4)
> from sympy import *
> a=Matrix([[1,4],[5,8]])
> b=Matrix([9,14])
> a.gauss_jordan_solve(b) (Matrix([
[ -4/3],
[31/12]]), Matrix(0, 1, []))
5)
> from sympy import *
> A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 10]])
> B = Matrix([3, 6, 9])
> sol, params = A.gauss_jordan_solve(B)
> sol
Matrix([
[-1],
[ 2],
[ 0]])
> params Matrix(0, 1, [])
Name:- kakade gorakshanath sandip
Class :- S.Y.B.Sc. (computer science)
Roll no:- 22
Practical No : 8
1)
> from sympy import *
> a=Matrix([[1,2,2],[2,1,2],[2,2,1]])
> print(a.eigenvals())
{5: 1, -1: 2}
2)
> from sympy import *
> b=Matrix([[22,31,31],[31,22,31],[31,31,22]])
> print(b.eigenvals())
{84: 1, -9: 2}
3)
> from sympy import *
> c=Matrix([[11,21,21],[21,11,21],[21,21,11]])
> print(c.eigenvals())
{53: 1, -10: 2}
4)
> from sympy import *
> d=Matrix([[31,44,44],[44,31,44],[44,44,31]])
> print(d.eigenvals())
{119: 1, -13: 2}
5)
> from sympy import *
> e=Matrix([[66,55,55],[55,66,55],[55,55,66]])
> print(e.eigenvals())
{176: 1, 11: 2}
Name:- kakade gorakshanath sandip
Class :- S.Y.B.Sc. (computer science)
Roll no:- 22
Practical No : 9
1)
> from sympy import *
> e=Matrix([[2,2,2],[0,2,2],[0,0,2]])
> print(e.eigenvects())
[(2, 3, [Matrix([
[1],
[0],
[0]])])]
2)
> from sympy import *
> g=Matrix([[88,98,98],[0,88,98],[0,0,88]])
> print(g.eigenvects())
[(88, 3, [Matrix([
[1],
[0],
[0]])])]
3)
4)
> from sympy import*
> b=Matrix([[1,2,0],[0,3,0],[2,-4,2]])
> b.is_diagonalizable()
True
5)
Practical No : 11
1)
>>>def falsePosition(f,x0,x1,e):
... x0=float(x0)
... x1=float(x1)
... e= float(e)
... if f(x0) * f(x1)>0.0:
... print('given guess values do not bracket the root.')
... print('try again')
... else:
... step = 1
... condition = True
... while condition:
... x2=x0-(x1-x0)*f(x0)/(f(x1)-f(x0))
... print('iteration %d,x2=%0.6f and f(x2)=%0.6f'%(step,x2,f(x2)))
... if f(x0) * f(x2)<0:
... x1=x2
... else:
... x0=x2
... step= step+1
... condition =abs(f(x2))>e
... print('\n Required root is :%0.8f'%x2)
...
>>> def f(x):
... return x**3-3*x+1
...
>>> falsePosition(f,0,1,0.00001)
Practical No : 12
1)
>>>def f(x):
... return sin(x)
...
>>> def trapezoidal(f,a,b,n):
... h= float(b-a)/n
... result =0.5*f(a)+0.5*f(b)
... for i in range(1,n):
... result +=f(a + i*h)
... result *=h
... return result
...
>>>def f(x):
... return sin(x)
...
>>>from math import *
>>>trapezoidal(f,0,pi,4)
1.89611889793704