math lab
math lab
Circle:-
from sympy import plot_implicit , symbols , Eq x , y = symbols ('x y') p1 = plot_implicit ( Eq ( x
** 2 + y ** 2 , 4 ) ,(x ,-4 , 4 ) ,(y ,-4 , 4 ) , title = 'Circle : $x^2+y^2=4$ ')
Strophoid:-
y 2 (a − x) = x 2 (a + x), a > 0 p3= plot_implicit ( Eq (( y ** 2 )*( 2-x ) , ( x ** 2 )*( 2+x ) ) , (x , -5
, 5 ) , (y , -5 , 5 ) , title = 'Strophoid : $y^2 (a-x)=x^2 (a+x), a> 0$ ')
lab-2
Find the angle between the curves r = 4(1 + cost) and r = 5(1 − cost).
from sympy import * r , t = symbols ('r,t'
r1=4*( 1+cos ( t ) ) ; # Input first polar curve r2=5*( 1-cos ( t ) )
dr1 = diff ( r1 , t )
dr2 = diff ( r2 , t )
t1=r1/dr1 t2=r2/dr2
q= solve ( r1-r2 , t )
w1=t1 . subs ({t: float ( q[1])})
w2=t2 . subs ({t: float ( q[1])})
y1= atan ( w1 )
y2= atan ( w2 )
w=abs( y1-y2 )
print ('Angle between curves in radians is %0.3f '%( w ) )
Find the angle between the curves r = 4 cost and r = 5 sin t.
from sympy import *
r , t = symbols ('r,t')
r1=4*(cos ( t ) ) ;
r2=5*(sin ( t ) ) ;
dr1 = diff ( r1 , t )
dr2 = diff ( r2 , t )
t1=r1/dr1
t2=r2/dr2
q= solve ( r1-r2 , t )
w1=t1 . subs ({t: float ( q[0])})
w2=t2 . subs ({t: float ( q[0])})
y1= atan ( w1 )
y2= atan ( w2 )
w=abs( y1-y2 )
print ('Angle between curves in radians is %0.4f '% float ( w ) )
lab 3:-
lab 4:-
lab 5:-
Solve: x 3 dy dx − x2 y + y4 cosx = 0.
x , y= symbols ('x,y')
y= Function ("y") ( x )
y1= Derivative (y , x )
display ( z1 )
lab 6:-
lab 8:-
Check whether the following system of homogenous linear equation has non-trivial solution.
x1 + 2x2 − x3 = 0, 2x1 + x2 + 4x3 = 0, 3x1 + 3x2 + 4x3 = 0.
import numpy as np
A=np . matrix ([[1 ,2 ,-1],[2 ,1 , 4],[3 ,3 , 4]])
B=np . matrix ([[0],[0],[0]])
r=np . linalg . matrix_rank ( A )
n=A . shape [1]
if ( r==n ):
print (" System has trivial solution ")
else :
print (" System has", n-r , "non - trivial solution (s)")
lab 9:-
Solve the system of equations using Gauss-Seidel method: 20x+y−2z = 17; 3x+20y−z = −18;
2x − 3y + 20z = 25.
f1 = lambda x ,y , z: ( 17-y+2*z )/20
f2 = lambda x ,y , z: (-18-3*x+z )/20
f3 = lambda x ,y , z: ( 25-2*x+3*y )/20
x0 = 0
y0 = 0
z0 = 0
count = 1
e = float ( input ('Enter tolerable error : ') )
print ('\ nCount \tx\ty\tz\n')
condition = True
while condition :
x1 = f1 ( x0 , y0 , z0 )
y1 = f2 ( x1 , y0 , z0 )
z1 = f3 ( x1 , y1 , z0 )
print ('%d\t%0.4f\t%0.4f\t%0.4f\n' %( count , x1 , y1 , z1 ) )
e1 = abs ( x0-x1 ) ;
e2 = abs ( y0-y1 ) ;
e3 = abs ( z0-z1 ) ;
count += 1
x0 = x1
y0 = y1
z0 = z1
condition = e1>e and e2>e and e3>e
print ('\ nSolution : x=%0.3f , y=%0.3f and z = %0.3f\n'% ( x1 , y1 , z1 ) )
lab 10:-
Obtain the eigen values and eigen vectors for the given matrix.
| 4 3 2|
|1 4 1|
|3 10 4|
import numpy as np
w , v = np . linalg .eig ( I )