0% found this document useful (0 votes)
18 views5 pages

math lab

Uploaded by

sashidari5
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
18 views5 pages

math lab

Uploaded by

sashidari5
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

Lab-1

 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:-

 If u = xy/z, v = yz/x, w = zx/y then prove that J = 4.


from sympy import *
x ,y , z= symbols ('x,y,z')
u=x*y/z
v=y*z/x
w=z*x/y
dux = diff (u , x )
duy = diff (u , y )
duz = diff (u , z )
dvx = diff (v , x )
dvy = diff (v , y )
dvz = diff (v , z )
dwx = diff (w , x )
dwy = diff (w , y )
dwz = diff (w , z )
J= Matrix ([[dux , duy , duz],[dvx , dvy , dvz],[dwx , dwy , dwz]]) ;
print ("The Jacobian matrix is \n")
display ( J )
Jac =det ( J ) . doit ()
print ('\n\n J = ', Jac )
 Prove that mixed partial derivatives , uxy = uyx for u = exp(x)(xcos(y) − ysin(y)).
from sympy import *
x , y = symbols ('x y')
u=exp( x )*( x*cos( y )-y*sin( y ) )
dux = diff (u , x )
duy = diff (u , y )
duxy = diff ( dux , y )
duyx = diff ( duy , x )
if duxy == duyx :
print ('Mixed partial derivatives are equal ')
else :
print ('Mixed partial derivatives are not equal ')

lab 4:-

 Find the Maxima and minima of f(x, y) = x 2 + y 2 + 3x − 3y + 4.


import sympy
from sympy import Symbol , solve , Derivative , pprint
x= Symbol ('x')
y= Symbol ('y')
f=x ** 2+x*y+y ** 2+3*x-3*y+4
d1= Derivative (f , x ) . doit ()
d2= Derivative (f , y ) . doit ()
criticalpoints1 = solve ( d1 )
criticalpoints2 = solve ( d2 )
s1= Derivative (f ,x , 2 ) . doit ()
s2= Derivative (f ,y , 2 ) . doit ()
s3= Derivative ( Derivative (f , y ) ,x ) . doit ()
print ('function value is ')
q1=s1 . subs ({y: criticalpoints1 , x: criticalpoints2 }) . evalf ()
q2=s2 . subs ({y: criticalpoints1 , x: criticalpoints2 }) . evalf ()
q3=s3 . subs ({y: criticalpoints1 , x: criticalpoints2 }) . evalf ()
delta =s1*s2-s3 ** 2
print ( delta , q1 )
if( delta >0 and s10 and s1>0 ):
print (" f takes minimum ")
elif ( delta >0 and s1>0 ):
print (" f takes minimum ")
if ( delta<0):
print ("The point is a saddle point ")
if ( delta ==0 ):
print (" further tests required ")

lab 5:-

 Solve: x 3 dy dx − x2 y + y4 cosx = 0.

from sympy import *

x , y= symbols ('x,y')

y= Function ("y") ( x )

y1= Derivative (y , x )

z1= dsolve ( Eq ( x ** 3*y1-x ** 2*y+y ** 4*cos ( x ) ,0 ) ,y )

display ( z1 )

 Solve dy dt = −ky with parameter k = 0.3 and y(0) = 5.


import numpy as np
from scipy . integrate
import odeint import matplotlib . pyplot as plt
def model (y , t ):
k=0 . 3
return -k*y
y0=5
t=np . linspace (0 , 20 )
y= odeint ( model , y0 , t )
plt . plot (t , y )
plt . title ('Solution of dy/dt= -ky; k=0.3, y(0)=5')
plt . xlabel ('time ')
plt . ylabel ('y(t)')
plt . show ()

lab 6:-

 Prove that 163 and 512 are relatively prime.


def gcd1 (a , b ):
c=1 ; if b 0 ):
c=b%a ;
print (a , c ) ;
b=a ;
a=c ;
continue
print ('GCD = ',b ) ;
gcd1 ( 163 , 512 )

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

I=np . array ([[4 ,3 , 2],[1 ,4 , 1],[3 , 10 , 4]])

print ("\n Given matrix : \n", I )

w , v = np . linalg .eig ( I )

print ("\n Eigen values : \n", w )

print ("\n Eigen vectors : \n", v )

print (" Eigen value :\n ", w[0])

print ("\n Corresponding Eigen vector :", v[:,0])

You might also like