B ) Finding the angle between the radius vector and the tangent , angle
between two curves.
# Angle between the radius vector and the tangent for the curve
# r=a*(1+cost) at t=pi/3
from sympy import *
a,t=symbols('a,t')
R=a*(1+cos(t))
dRdt=diff(R,t)
R=R.subs(t,pi/3)
dRdt=dRdt.subs(t,pi/3)
PHI=atan(R/dRdt)
if PHI<0:
PHI=PHI+pi
print('The angle between the radius vector and the tangent =',PHI)
C ) Find the angle between the curves r =a(1−cos t) and r =2 a cos t at
1
t=acos ( )
3
from sympy import *
a,t=symbols('a,t')
R=a*(1-cos(t))
dRdt=diff(R,t)
R=R.subs(t,acos(1/3))
dRdt=dRdt.subs(t,acos(1/3))
PHI=atan(R/dRdt)
if PHI<0:
PHI=PHI+pi
r=2*a*cos(t)
drdt=diff(r,t)
r=r.subs(t,acos(1/3))
drdt=drdt.subs(t,acos(1/3))
phi=atan(r/drdt)
if phi <0:
phi=phi+pi
print('The angle of intersection =',abs(PHI-phi))
3. Finding partial derivatives, Jacobian and plotting the graph
−1 y
A) Findu x , u yx , u xx , u xy for u=tan ( x )
from sympy import *
import matplotlib.pyplot as plt
var('x y')
u=atan(y/x)
ux=simplify(diff(u,x))
uy=simplify(diff(u,y))
uxy=simplify(diff(ux,y))
uxx=simplify(diff(u,x,2))
uyx=simplify(diff(u,x,y))
print('The required partial derivatives:')
print('ux=',ux)
print('uy=',uy)
print('uxy=',uxy)
print('uyx=',uyx)
print('uxx=',uxx)
2 2
y x ∂f ∂f ∂ x ∂ f
B) If f ( x , y )=x + y , find ,
∂x ∂ y
∧also show that 2 = 2
∂x ∂ y
from sympy import *
var('x y')
f=x**y+y**x
fx=simplify(diff(f,x))
fy=simplify(diff(f,y))
fxx=simplify(diff(f,x,2))
fyy=simplify(diff(f,y,2))
print('The required partial derivatives:')
print('fx=',fx)
print('fy=',fy)
print('fxx=',fxx)
print('fyy=',fyy)
C) Jacobian of a given function
∂(u , v )
If u=2 x−3 y , v =5 x + 4 y find ∂(x , y )
from sympy import *
import numpy as np
import matplotlib.pyplot as plt
var('x y')
u=2*x-3*y
v=5*x+4*y
A=Matrix([u,v])
Jmatrix=A.jacobian([x,y])
print('Jacobian matrix-')
pprint(Jmatrix)
J=det(Jmatrix)
print(' Jacobian =', J)
4. Solution of first order differential equation and plotting the graphs
dy 2 3
A) Solve dx − x y =x with y(1)=0 and verify using Python code.
from sympy import *
import matplotlib.pyplot as plt
x=symbols('x')
y=Function('y')
deq=Derivative(y(x),x)-2*y(x)/x-x**3
ysoln=simplify(dsolve(deq,y(x),ics={y(1):0},hint='1st_linear'))
print("The solution of given differential equation is:")
pprint(simplify(ysoln))
plot(ysoln.rhs,(x,-2,2))
dy 2
B) Solve x dx + y= y log x with y(1)=1 and verify using Python code.
from sympy import *
import matplotlib.pyplot as plt
x=symbols('x')
y=Function('y')
deq=x*Derivative(y(x),x)+y(x)-log(x)*y(x)**2
ysoln=dsolve(deq,y(x),ics={y(1):1},hint='Bernoulli')
print("The solution of the given differential equation is:")
pprint(ysoln)
plot(ysoln.rhs,(x,1,5))