Lab Set 6 and 7
Lab Set 6 and 7
Output:
(𝑥cos(𝑦)−𝑦sin(𝑦))
0
Output:
The Jacobian matrix is
1 6𝑦 −3𝑧 2
8𝑥𝑦𝑧 4𝑥 2 𝑧 4𝑥 2 𝑦
−𝑦 −𝑥 4𝑧
J=
4𝑥 3 𝑦 − 24𝑥 2 𝑦 3 + 12𝑥 2 𝑦𝑧 3 + 16𝑥 2 𝑧 2 − 192𝑥𝑦 2 𝑧 2
J at (1,-1,0):
20
Maths Python Lab
Lab Set 7: Applications of taylor's series expansion and
L'Hospital's Rule.
1.Expand sin(x) as Taylor series about x=pi/2 upto 3rd degree term.
Also find 𝑠𝑖𝑛(1000 )
Program Code:
import numpy as np
from matplotlib import pyplot as plt
from sympy import*
x=Symbol('x')
y=sin(1*x)
x0=float(pi/2)
dy=diff(y,x)
d2y=diff(y,x,2)
d3y=diff(y,x,3)
yat=lambdify(x,y)
dyat=lambdify(x,dy)
d2yat=lambdify(x,d2y)
d3yat=lambdify(x,d3y)
y=yat(x0)+((x-x0)/2)*dyat(x0)+((x-x0)**2/6)*d2yat(x0)+((x-x0)**3/24)*d3yat(x0)
print(simplify(y))
yat=lambdify(x,y)
print("%.3f"% yat(pi/2+10*(pi/180)))
def f(x):
return np.sin(1*x)
x=np.linspace(-10,10)
plt.plot(x,yat(x),color='red')
plt.plot(x,f(x),color='green')
plt.ylim([-3,3])
plt.grid()
plt.show()
Output:
-2.55134749822365e-18*x**3 - 0.166666666666667*x**2 + 0.523598775598299*x + 0.588766483287943
0.995
2.Find the Maclaurin series expansion of sin(x)+cos(x) upto 3rd degree
term. Calculate sin(10)+cos(10).
Program Code:
import numpy as np
from matplotlib import pyplot as plt
from sympy import*
x=Symbol('x')
y=sin(x)+cos(x)
format
x0=float(0)
dy=diff(y,x)
d2y=diff(y,x,2)
d3y=diff(y,x,3)
yat=lambdify(x,y)
dyat=lambdify(x,dy)
d2yat=lambdify(x,d2y)
d3yat=lambdify(x,d3y)
y=yat(x0)+((x-x0)/2)*dyat(x0)+((x-x0)**2/6)*d2yat(x0)+((x-x0)**3/24)*d3yat(x0)
print(simplify(y))
yat=lambdify(x,y)
print("%.3f"% yat(pi/2+10*(pi/180)))
def f(x):
return np.sin(1*x)+np.cos(x)
x=np.linspace(-10,10)
plt.plot(x,yat(x),color='red')
plt.plot(x,f(x),color='green')
plt.ylim([-3,3])
plt.grid()
plt.show()
Output:
-0.0416666666666667*x**3 - 0.166666666666667*x**2 + 0.5*x + 1.0
1.143
sin
(𝑥)
3.lim𝑥→0
𝑥
Program Code:
from sympy import Limit,Symbol,exp,sin
x=Symbol('x')
l=Limit((sin(x))/x,x,0).doit()
print(l)
Output:
1
Program Code:
from sympy import*
x=Symbol('x')
l=Limit((5*x**4-4*x**2-1)/(10-x-9*x**3),x,1).doit()
print(l)
Output:
-3/7
1 𝑥
5.𝑃𝑟𝑜𝑣𝑒 𝑡ℎ𝑎𝑡 lim𝑥→∞ 1 + =𝑒
𝑥
Program Code:
from sympy import *
import numpy as np
x=Symbol('x')
l=Limit((1+1/x)**x,x,np.inf).doit()
display(l)
Output:
e