Chapter 4: Diffrentiations And Applications

Example 4.1, page no. 133

In [24]:
import sympy
import numpy
import math

print "We have to find yn for F=cosxcos2xcos3x"
x = sympy.Symbol('x')
F = sympy.cos(x)*sympy.cos(2*x)*sympy.cos(3*x)
n = int(raw_input("Enter the order of differentiation: "))
print "calculating yn.."
yn= sympy.diff(F,x,n)
print "The expression for yn is"
print yn 
We have to find yn for F=cosxcos2xcos3x
Enter the order of differentiation: 0
calculating yn..
The expression for yn is
cos(x)*cos(2*x)*cos(3*x)

Example 4.5, page no. 137

In [25]:
import sympy

print 'we have to find yn for F=cosxcos2xcos3x'
x = sympy.Symbol('x')
F = x/((x-1)*(2*x+3))
n = int(raw_input("Enter the order of differentiation: "))
print "calculating yn"
yn= sympy.diff(F,x,n)
print "The expression for yn is"
print yn
we have to find yn for F=cosxcos2xcos3x
Enter the order of differentiation: 0
calculating yn
The expression for yn is
x/((x - 1)*(2*x + 3))

Example 4.6, page no. 138

In [26]:
import sympy

print "We have to find yn for F=cosxcos2xcos3x"
x = sympy.Symbol('x')
a = sympy.Symbol('a')
F = x/(x**2+a**2)
n = raw_input ("Enter the orde of  differentiation:")
print "calculating yn"
yn = diff(F,x,n)
print "the expression for yn is"
print yn
We have to find yn for F=cosxcos2xcos3x
Enter the orde of  differentiation:0
calculating yn
the expression for yn is
x/(a**2 + x**2)

Example 4.7, page no. 139

In [27]:
import sympy, math

print "we have to find yn for F=cosxcos2xcos3x"
x = sympy.Symbol('x')
a = sympy.Symbol('a')
F = math.e**(x)*(2*x+3)**3
n = raw_input ("Enter the order of  differentiation: ")
print "calculating yn"
yn = diff(F,x,n)
print "the expression for yn is"
print yn
we have to find yn for F=cosxcos2xcos3x
Enter the order of  differentiation: 0
calculating yn
the expression for yn is
2.71828182845905**x*(2*x + 3)**3

Example 4.8, page no. 139

In [20]:
import sympy

print 'y=(sinˆ-1)x) --sign inverse x'
x = sympy.Symbol('x')
a = sympy.Symbol('a')
y = (sympy.asin(x))**2;
print 'we have to prove (1-xˆ2)y(n+2)-(2n+1)xy(n+1)-nˆ2 yn'
print 'Calculating yn for various values of n'
for n in range(1,5):
    F=(1-x**2)*sympy.diff(y,x,n+2)-(2*n+1)*x*sympy.diff(y,x,n+1)-(n**2+a**2)*sympy.diff(y,x,n)
    print n
    print 'The expression for yn is'
    print F
    print 'Which is equal to 0'
print 'Hence Proved'
y=(sinˆ-1)x) --sign inverse x
we have to prove (1-xˆ2)y(n+2)-(2n+1)xy(n+1)-nˆ2 yn
Calculating yn for various values of n
1
The expression for yn is
-6*x*(x*asin(x)/(-x**2 + 1)**(3/2) - 1/(x**2 - 1)) - 2*(a**2 + 1)*asin(x)/sqrt(-x**2 + 1) + 2*(-x**2 + 1)*(3*x**2*asin(x)/(-x**2 + 1)**(5/2) + 3*x/(x**2 - 1)**2 + asin(x)/(-x**2 + 1)**(3/2))
Which is equal to 0
2
The expression for yn is
-10*x*(3*x**2*asin(x)/(-x**2 + 1)**(5/2) + 3*x/(x**2 - 1)**2 + asin(x)/(-x**2 + 1)**(3/2)) - 2*(a**2 + 4)*(x*asin(x)/(-x**2 + 1)**(3/2) - 1/(x**2 - 1)) + 2*(-x**2 + 1)*(15*x**3*asin(x)/(-x**2 + 1)**(7/2) - 15*x**2/(x**2 - 1)**3 + 9*x*asin(x)/(-x**2 + 1)**(5/2) + 4/(x**2 - 1)**2)
Which is equal to 0
3
The expression for yn is
-14*x*(15*x**3*asin(x)/(-x**2 + 1)**(7/2) - 15*x**2/(x**2 - 1)**3 + 9*x*asin(x)/(-x**2 + 1)**(5/2) + 4/(x**2 - 1)**2) - 2*(a**2 + 9)*(3*x**2*asin(x)/(-x**2 + 1)**(5/2) + 3*x/(x**2 - 1)**2 + asin(x)/(-x**2 + 1)**(3/2)) + 2*(-x**2 + 1)*(105*x**4*asin(x)/(-x**2 + 1)**(9/2) + 105*x**3/(x**2 - 1)**4 + 90*x**2*asin(x)/(-x**2 + 1)**(7/2) - 55*x/(x**2 - 1)**3 + 9*asin(x)/(-x**2 + 1)**(5/2))
Which is equal to 0
4
The expression for yn is
-18*x*(105*x**4*asin(x)/(-x**2 + 1)**(9/2) + 105*x**3/(x**2 - 1)**4 + 90*x**2*asin(x)/(-x**2 + 1)**(7/2) - 55*x/(x**2 - 1)**3 + 9*asin(x)/(-x**2 + 1)**(5/2)) - 2*(a**2 + 16)*(15*x**3*asin(x)/(-x**2 + 1)**(7/2) - 15*x**2/(x**2 - 1)**3 + 9*x*asin(x)/(-x**2 + 1)**(5/2) + 4/(x**2 - 1)**2) + 2*(-x**2 + 1)*(945*x**5*asin(x)/(-x**2 + 1)**(11/2) - 945*x**4/(x**2 - 1)**5 + 1050*x**3*asin(x)/(-x**2 + 1)**(9/2) + 735*x**2/(x**2 - 1)**4 + 225*x*asin(x)/(-x**2 + 1)**(7/2) - 64/(x**2 - 1)**3)
Which is equal to 0
Hence Proved

Example 4.9, page no. 140

In [2]:
import sympy, math

print 'y=eˆ(a(sinˆ-1)x))--sign inverse x'
x = sympy.Symbol('x')
a = sympy.Symbol('a')
y = math.e**(a*(sympy.asin(x)))
print 'We have to prove (1-xˆ2)y(n+2)-(2n+1)xy(n+1)-(nˆ2+aˆ2)yn'
print 'Calculating yn for various values of n'
for n in range(1,5):
    F =(1-x**2)*sympy.diff(y,x,n+2)-(2*n+1)*x*sympy.diff(y,x,n+1)-(n**2+a**2)*sympy.diff(y,x,n)
    print n
    print 'The expression for yn is'
    print F
    print 'Which is equal to 0'
print 'Hence proved'
y=eˆ(a(sinˆ-1)x))--sign inverse x
We have to prove (1-xˆ2)y(n+2)-(2n+1)xy(n+1)-(nˆ2+aˆ2)yn
Calculating yn for various values of n
1
The expression for yn is
-3.0*2.71828182845905**(a*asin(x))*a*x*(-a/(x**2 - 1) + x/(-x**2 + 1)**(3/2)) - 1.0*2.71828182845905**(a*asin(x))*a*(a**2 + 1)/sqrt(-x**2 + 1) + 2.71828182845905**(a*asin(x))*a*(-x**2 + 1)*(1.0*a**2/(-x**2 + 1)**(3/2) + 3.0*a*x/(x**2 - 1)**2 + 3.0*x**2/(-x**2 + 1)**(5/2) + 1.0/(-x**2 + 1)**(3/2))
Which is equal to 0
2
The expression for yn is
-5*2.71828182845905**(a*asin(x))*a*x*(1.0*a**2/(-x**2 + 1)**(3/2) + 3.0*a*x/(x**2 - 1)**2 + 3.0*x**2/(-x**2 + 1)**(5/2) + 1.0/(-x**2 + 1)**(3/2)) - 1.0*2.71828182845905**(a*asin(x))*a*(a**2 + 4)*(-a/(x**2 - 1) + x/(-x**2 + 1)**(3/2)) + 2.71828182845905**(a*asin(x))*a*(-x**2 + 1)*(1.0*a**3/(x**2 - 1)**2 + 6.0*a**2*x/(-x**2 + 1)**(5/2) - 15.0*a*x**2/(x**2 - 1)**3 + 4.0*a/(x**2 - 1)**2 + 15.0*x**3/(-x**2 + 1)**(7/2) + 9.0*x/(-x**2 + 1)**(5/2))
Which is equal to 0
3
The expression for yn is
-7*2.71828182845905**(a*asin(x))*a*x*(1.0*a**3/(x**2 - 1)**2 + 6.0*a**2*x/(-x**2 + 1)**(5/2) - 15.0*a*x**2/(x**2 - 1)**3 + 4.0*a/(x**2 - 1)**2 + 15.0*x**3/(-x**2 + 1)**(7/2) + 9.0*x/(-x**2 + 1)**(5/2)) - 2.71828182845905**(a*asin(x))*a*(a**2 + 9)*(1.0*a**2/(-x**2 + 1)**(3/2) + 3.0*a*x/(x**2 - 1)**2 + 3.0*x**2/(-x**2 + 1)**(5/2) + 1.0/(-x**2 + 1)**(3/2)) + 2.71828182845905**(a*asin(x))*a*(-x**2 + 1)*(1.0*a**4/(-x**2 + 1)**(5/2) - 10.0*a**3*x/(x**2 - 1)**3 + 45.0*a**2*x**2/(-x**2 + 1)**(7/2) + 10.0*a**2/(-x**2 + 1)**(5/2) + 105.0*a*x**3/(x**2 - 1)**4 - 55.0*a*x/(x**2 - 1)**3 + 105.0*x**4/(-x**2 + 1)**(9/2) + 90.0*x**2/(-x**2 + 1)**(7/2) + 9.0/(-x**2 + 1)**(5/2))
Which is equal to 0
4
The expression for yn is
-9*2.71828182845905**(a*asin(x))*a*x*(1.0*a**4/(-x**2 + 1)**(5/2) - 10.0*a**3*x/(x**2 - 1)**3 + 45.0*a**2*x**2/(-x**2 + 1)**(7/2) + 10.0*a**2/(-x**2 + 1)**(5/2) + 105.0*a*x**3/(x**2 - 1)**4 - 55.0*a*x/(x**2 - 1)**3 + 105.0*x**4/(-x**2 + 1)**(9/2) + 90.0*x**2/(-x**2 + 1)**(7/2) + 9.0/(-x**2 + 1)**(5/2)) - 2.71828182845905**(a*asin(x))*a*(a**2 + 16)*(1.0*a**3/(x**2 - 1)**2 + 6.0*a**2*x/(-x**2 + 1)**(5/2) - 15.0*a*x**2/(x**2 - 1)**3 + 4.0*a/(x**2 - 1)**2 + 15.0*x**3/(-x**2 + 1)**(7/2) + 9.0*x/(-x**2 + 1)**(5/2)) + 2.71828182845905**(a*asin(x))*a*(-x**2 + 1)*(-1.0*a**5/(x**2 - 1)**3 + 15.0*a**4*x/(-x**2 + 1)**(7/2) + 105.0*a**3*x**2/(x**2 - 1)**4 - 20.0*a**3/(x**2 - 1)**3 + 420.0*a**2*x**3/(-x**2 + 1)**(9/2) + 195.0*a**2*x/(-x**2 + 1)**(7/2) - 945.0*a*x**4/(x**2 - 1)**5 + 735.0*a*x**2/(x**2 - 1)**4 - 64.0*a/(x**2 - 1)**3 + 945.0*x**5/(-x**2 + 1)**(11/2) + 1050.0*x**3/(-x**2 + 1)**(9/2) + 225.0*x/(-x**2 + 1)**(7/2))
Which is equal to 0
Hence proved

Example 4.10, page no. 141

In [4]:
import sympy

print 'y^(1/m)+y^-(1/m)=2x'
print 'OR y^(2/m)-2xy^(1/m)+1'
print 'OR y=[ x+(xˆ2-1)]ˆm and y=[x-(xˆ2 −1)]ˆm'
x = sympy.Symbol('x')
m = sympy.Symbol('m')
print 'For y=[x+(xˆ2−1)]ˆm'
y=(x+(x**2-1))**m
print 'We have to prove (xˆ2−1)y(n+2)+(2n+1)xy(n+1)+(nˆ2−mˆ2)yn'
print 'Calculating various values for yn'
for n in range(1,5):
    F=(x**2-1)*sympy.diff(y,x,n+2)+(2*n+1)*x*sympy.diff(y,x,n+1)+(n**2-m**2)*sympy.diff(y,x,n)
    print n
    print 'The expression for yn is'
    print F
    print 'Which is equal to 0'
print 'Hence Proved'
y^(1/m)+y^-(1/m)=2x
OR y^(2/m)-2xy^(1/m)+1
OR y=[ x+(xˆ2-1)]ˆm and y=[x-(xˆ2 −1)]ˆm
For y=[x+(xˆ2−1)]ˆm
We have to prove (xˆ2−1)y(n+2)+(2n+1)xy(n+1)+(nˆ2−mˆ2)yn
Calculating various values for yn
1
The expression for yn is
3*m*x*(x**2 + x - 1)**m*(m*(2*x + 1)**2/(x**2 + x - 1) - (2*x + 1)**2/(x**2 + x - 1) + 2)/(x**2 + x - 1) + m*(-m**2 + 1)*(2*x + 1)*(x**2 + x - 1)**m/(x**2 + x - 1) + m*(2*x + 1)*(x**2 - 1)*(x**2 + x - 1)**m*(m**2*(2*x + 1)**2/(x**2 + x - 1) - 3*m*(2*x + 1)**2/(x**2 + x - 1) + 6*m + 2*(2*x + 1)**2/(x**2 + x - 1) - 6)/(x**2 + x - 1)**2
Which is equal to 0
2
The expression for yn is
5*m*x*(2*x + 1)*(x**2 + x - 1)**m*(m**2*(2*x + 1)**2/(x**2 + x - 1) - 3*m*(2*x + 1)**2/(x**2 + x - 1) + 6*m + 2*(2*x + 1)**2/(x**2 + x - 1) - 6)/(x**2 + x - 1)**2 + m*(-m**2 + 4)*(x**2 + x - 1)**m*(m*(2*x + 1)**2/(x**2 + x - 1) - (2*x + 1)**2/(x**2 + x - 1) + 2)/(x**2 + x - 1) + m*(x**2 - 1)*(x**2 + x - 1)**m*(m**3*(2*x + 1)**4/(x**2 + x - 1)**2 - 6*m**2*(2*x + 1)**4/(x**2 + x - 1)**2 + 12*m**2*(2*x + 1)**2/(x**2 + x - 1) + 11*m*(2*x + 1)**4/(x**2 + x - 1)**2 - 36*m*(2*x + 1)**2/(x**2 + x - 1) + 12*m - 6*(2*x + 1)**4/(x**2 + x - 1)**2 + 24*(2*x + 1)**2/(x**2 + x - 1) - 12)/(x**2 + x - 1)**2
Which is equal to 0
3
The expression for yn is
7*m*x*(x**2 + x - 1)**m*(m**3*(2*x + 1)**4/(x**2 + x - 1)**2 - 6*m**2*(2*x + 1)**4/(x**2 + x - 1)**2 + 12*m**2*(2*x + 1)**2/(x**2 + x - 1) + 11*m*(2*x + 1)**4/(x**2 + x - 1)**2 - 36*m*(2*x + 1)**2/(x**2 + x - 1) + 12*m - 6*(2*x + 1)**4/(x**2 + x - 1)**2 + 24*(2*x + 1)**2/(x**2 + x - 1) - 12)/(x**2 + x - 1)**2 + m*(-m**2 + 9)*(2*x + 1)*(x**2 + x - 1)**m*(m**2*(2*x + 1)**2/(x**2 + x - 1) - 3*m*(2*x + 1)**2/(x**2 + x - 1) + 6*m + 2*(2*x + 1)**2/(x**2 + x - 1) - 6)/(x**2 + x - 1)**2 + m*(2*x + 1)*(x**2 - 1)*(x**2 + x - 1)**m*(m**4*(2*x + 1)**4/(x**2 + x - 1)**2 - 10*m**3*(2*x + 1)**4/(x**2 + x - 1)**2 + 20*m**3*(2*x + 1)**2/(x**2 + x - 1) + 35*m**2*(2*x + 1)**4/(x**2 + x - 1)**2 - 120*m**2*(2*x + 1)**2/(x**2 + x - 1) + 60*m**2 - 50*m*(2*x + 1)**4/(x**2 + x - 1)**2 + 220*m*(2*x + 1)**2/(x**2 + x - 1) - 180*m + 24*(2*x + 1)**4/(x**2 + x - 1)**2 - 120*(2*x + 1)**2/(x**2 + x - 1) + 120)/(x**2 + x - 1)**3
Which is equal to 0
4
The expression for yn is
9*m*x*(2*x + 1)*(x**2 + x - 1)**m*(m**4*(2*x + 1)**4/(x**2 + x - 1)**2 - 10*m**3*(2*x + 1)**4/(x**2 + x - 1)**2 + 20*m**3*(2*x + 1)**2/(x**2 + x - 1) + 35*m**2*(2*x + 1)**4/(x**2 + x - 1)**2 - 120*m**2*(2*x + 1)**2/(x**2 + x - 1) + 60*m**2 - 50*m*(2*x + 1)**4/(x**2 + x - 1)**2 + 220*m*(2*x + 1)**2/(x**2 + x - 1) - 180*m + 24*(2*x + 1)**4/(x**2 + x - 1)**2 - 120*(2*x + 1)**2/(x**2 + x - 1) + 120)/(x**2 + x - 1)**3 + m*(-m**2 + 16)*(x**2 + x - 1)**m*(m**3*(2*x + 1)**4/(x**2 + x - 1)**2 - 6*m**2*(2*x + 1)**4/(x**2 + x - 1)**2 + 12*m**2*(2*x + 1)**2/(x**2 + x - 1) + 11*m*(2*x + 1)**4/(x**2 + x - 1)**2 - 36*m*(2*x + 1)**2/(x**2 + x - 1) + 12*m - 6*(2*x + 1)**4/(x**2 + x - 1)**2 + 24*(2*x + 1)**2/(x**2 + x - 1) - 12)/(x**2 + x - 1)**2 + m*(x**2 - 1)*(x**2 + x - 1)**m*(m**5*(2*x + 1)**6/(x**2 + x - 1)**3 - 15*m**4*(2*x + 1)**6/(x**2 + x - 1)**3 + 30*m**4*(2*x + 1)**4/(x**2 + x - 1)**2 + 85*m**3*(2*x + 1)**6/(x**2 + x - 1)**3 - 300*m**3*(2*x + 1)**4/(x**2 + x - 1)**2 + 180*m**3*(2*x + 1)**2/(x**2 + x - 1) - 225*m**2*(2*x + 1)**6/(x**2 + x - 1)**3 + 1050*m**2*(2*x + 1)**4/(x**2 + x - 1)**2 - 1080*m**2*(2*x + 1)**2/(x**2 + x - 1) + 120*m**2 + 274*m*(2*x + 1)**6/(x**2 + x - 1)**3 - 1500*m*(2*x + 1)**4/(x**2 + x - 1)**2 + 1980*m*(2*x + 1)**2/(x**2 + x - 1) - 360*m - 120*(2*x + 1)**6/(x**2 + x - 1)**3 + 720*(2*x + 1)**4/(x**2 + x - 1)**2 - 1080*(2*x + 1)**2/(x**2 + x - 1) + 240)/(x**2 + x - 1)**3
Which is equal to 0
Hence Proved

Example 4.11, page no. 144

In [7]:
import sympy, math

print 'For roles theorem F9x should be differentiable in (a, b) and f(a)=f(b)'
print 'Here f(x)=sin(x)/e^x'
x = sympy.Symbol('x')
y = sympy.sin(x)/math.e**x
y1 = sympy.diff(y,x)
print y1
print 'Putting this to zero we get tan(x)=1 ie x=pi/4'
print 'Value pi/2 lies b/w 0 and pi. Hence roles theroem is verified'
For roles theorem F9x should be differentiable in (a, b) and f(a)=f(b)
Here f(x)=sin(x)/e^x
-1.0*2.71828182845905**(-x)*sin(x) + 2.71828182845905**(-x)*cos(x)
Putting this to zero we get tan(x)=1 ie x=pi/4
Value pi/2 lies b/w 0 and pi. Hence roles theroem is verified

Example 4.16 page no. 149

In [56]:
import numpy, sympy, math

print "Maclaurin's Series"
print 'f(x)=f(0)+xf1(0)+xˆ2/2!∗f2(0)+xˆ3/3!∗f3(0)+......'
x = sympy.Symbol('x')
a = sympy.Symbol('a')
y = sympy.tan(a)
n = int(raw_input("Enter the orde of  differentiation: "))
a = 1
t = sympy.solve(y)[0]
a = 0
for i in range(2,n+1):
    y1 = sympy.diff (y,'a',i-1)
    if sympy.solve(y1):
        t = t+x**(i-1)*sympy.solve(y1)[0]/math.factorial(i-1)
print t
Maclaurin's Series
f(x)=f(0)+xf1(0)+xˆ2/2!∗f2(0)+xˆ3/3!∗f3(0)+......
Enter the orde of  differentiation: 6
-I*x**5*atanh(sqrt(-sqrt(105)/30 + 1/2))/120 - I*x**3*atanh(sqrt(3)/3)/6

Example 4.17, page no. 150

In [2]:
import numpy,sympy,math

print "Maclaurins series"
print "f(x)=f(0)+xf1(0)+xˆ2/2!∗f2(0)+xˆ3/3!∗f3(0)+......"
x = sympy.Symbol('x')
a = sympy.Symbol('a')
y = math.e**(sympy.sin(a))
n = int(raw_input('enter the number of expression in series:'))
a = 0
t = 0
a = 0
for i in range(2,n+1):
    y1 = sympy.diff(y,'a',i-1) 
    t = t+x**(i-1)*sympy.solve(y1)[0]/math.factorial(i-1) 
print t
Maclaurins series
f(x)=f(0)+xf1(0)+xˆ2/2!∗f2(0)+xˆ3/3!∗f3(0)+......
enter the number of expression in series:2
1.5707963267949*x

Example 4.18, page no. 150

In [10]:
import numpy,sympy,math

print "Maclaurins series"
print "f(x)=f(0)+xf1(0)+xˆ2/2!∗f2(0)+xˆ3/3!∗f3(0)+......"
x = sympy.Symbol('x')
a = sympy.Symbol('a')
y = sympy.log(1+(sympy.sin(a))**2)
n = int(raw_input("enter the number of differentiation involved in maclaurins series :"))
a = 0
t = 0
a = 0
for i in range(2,n+1):
    y1 = sympy.diff(y,'a',i-1) 
    t = t+x**(i-1)*sympy.solve(y1)[0]/math.factorial(i-1) 
print t
Maclaurins series
f(x)=f(0)+xf1(0)+xˆ2/2!∗f2(0)+xˆ3/3!∗f3(0)+......
enter the number of differentiation involved in maclaurins series :3
x**2*atan(RootOf(tan(a/2)**4 - 10*tan(a/2)**2 + 1, 0))

Example 4.19, page no. 151

In [33]:
import numpy,sympy,math

print "Maclaurins series"
print "f(x)=f(0)+xf1(0)+xˆ2/2!∗f2(0)+xˆ3/3!∗f3(0)+......"
x = sympy.Symbol('x')
a = sympy.Symbol('a')
b = sympy.Symbol('b')
y = math.e**(a*sympy.asin(b))
y1 = sympy.diff(y, 'b', 1)
n = int(raw_input("enter the number of expression in series :"))
b = 0
t = 0
for i in range(2,n+1):
    y1 = sympy.diff(y,'b',i-1) 
    t = t+x**(i-1)*y1.evalf()/math.factorial(i-1) 
print t
Maclaurins series
f(x)=f(0)+xf1(0)+xˆ2/2!∗f2(0)+xˆ3/3!∗f3(0)+......
enter the number of expression in series :2
1.0*2.71828182845905**(a*asin(b))*a*x*(-b**2 + 1.0)**(-0.5)

Example 4.20, page no. 152

In [3]:
import numpy,math,sympy

print "Use of taylor series are given in subsequent examples"
y = math.log(1.1)
print "log(1.1) = ",math.log (1.1) 
Advantage of scilab is that we can calculate log1.1 directly without using Taylor series
Use of taylor series are given in subsequent examples
log(1.1) =  0.0953101798043

Example 4.21, page no. 152

In [29]:
import numpy,sympy,math

print "Taylor series"
print "f(x+h)=f(x)+hf1(x)+hˆ2/2!∗f2(x)+hˆ3/3!∗f3(x)+......"
print "To finf the taylor expansion of tan−1(x+h)"
x = sympy.Symbol('x')
h = sympy.Symbol('h')
y = sympy.atan ( x )
n = int(raw_input ("enter the number of expression in series : "))
t = y 
for i in range (2,n+1):
    y1 = sympy.diff (y,'x',i-1)
    t = t+h**(i-1)*(y1)/math.factorial(i-1)
print t
Taylor series
f(x+h)=f(x)+hf1(x)+hˆ2/2!∗f2(x)+hˆ3/3!∗f3(x)+......
To finf the taylor expansion of tan−1(x+h)
enter the number of expression in series : 2
h/(x**2 + 1) + atan(x)

Example 4.22, page no. 153

In [38]:
import numpy,sympy,math

print "Here we need to find the limit off(x) at x=0"
x = sympy.Symbol('x')
y = (x*math.e**x-sympy.log(1+x))/x**2
f = 1
while f==1:
    yn = x*math.e**x-sympy.log(1+x)
    yd = x**2;
    yn1 = sympy.diff(yn,'x',1)
    yd1 = sympy.diff(yd,'x',1)
    x = 0
    a = yn1.evalf(subs=dict(x=1))
    b = yd1.evalf(subs=dict(x=1))
    if a == b:
        yn = yn1 
        yd = yd1 
    else:
        f =0
h = a / b 
print h
Here we need to find the limit off(x) at x=0
2.46828182845905

Example 4.32, page no. 162

In [12]:
import numpy,sympy,math

print "Equation of tangent"
x = sympy.Symbol('x')
a = sympy.Symbol('a')
y = sympy.Symbol('y')
f = (a**(2/3)-x**(2/3))**(3/2)
s = sympy.diff(f,x)
Y1 = s*(-x)+y
X1 = -y/s*x
g = x-(Y1-s*(X1-x))
print "Equation is g=0 where g is",g
Equation of tangent
Equation is g=0 where g is x - y

Example, 4.34, page no. 163

In [13]:
import numpy,sympy,math

print "Equation of tangent"
x = sympy.Symbol('x')
a = sympy.Symbol('a')
y = sympy.Symbol('y')
t = sympy.Symbol('t')
xo = a*(sympy.cos(t)+t*sympy.sin(t))
yo = a*(sympy.sin(t)-t*sympy.cos(t))
s = sympy.diff(xo,t)/sympy.diff(yo,t)
y = yo+s*(x-xo)
print "y = ",y
Equation of tangent
y =  a*(-t*cos(t) + sin(t)) + (-a*(t*sin(t) + cos(t)) + x)*cos(t)/sin(t)

Example 4.35, page no. 163

In [32]:
import numpy,sympy,math

print "The two given curves are xˆ=4y and yˆ2=4x which intersects at (0,0) and (4,4)"
print "for (4 ,4)"
x = 4
x = sympy.Symbol('x')
y1= x**2/4
y2 = 2*x**(1/2)
m1= sympy.diff(y1,x,1)
m2= sympy.diff(y2,x,1)
x = 4
print "Angle between them is (radians):−"
t= sympy.atan((m1-m2)/(1+m1*m2)) 
print t
The two given curves are xˆ=4y and yˆ2=4x which intersects at (0,0) and (4,4)
for (4 ,4)
Angle between them is (radians):−
atan(x/2)

Example 4.37, page no. 165

In [50]:
import numpy,sympy,math

a = sympy.Symbol('a')
t = sympy.Symbol('t')
x = a*(sympy.cos(t)+sympy.log(sympy.tan(t/2)))
y = a*sympy.sin(t)
s = sympy.diff(x,t,1)/sympy.diff(y,t,1)
print "length of tangent"
l = y*(1+s)**(0.5)
print l
print "checking for its dependency on t"
f = 1
t = 0
k = sympy.solve(l)
for i in range(1,11):
    t = i
    if(sympy.solve(l)!=k):
        f = 0
if(f==1):
    print "verified and equal to a"
print "subtangent"
m = y/s
print m
length of tangent
a*(((tan(t/2)**2/2 + 1/2)/tan(t/2) - sin(t))/cos(t) + 1)**0.5*sin(t)
checking for its dependency on t
verified and equal to a
subtangent
a*sin(t)*cos(t)/((tan(t/2)**2/2 + 1/2)/tan(t/2) - sin(t))

Example 4.39, page no. 168

In [39]:
import numpy,sympy,math

print "Angle of intersection"
print "point of intersection of r=sint+cost and r=2 sint is t=pi/4"
print "tanu=dQ/dr∗r"
Q = sympy.Symbol('Q')
r1 = 2*sympy.sin(Q)
r2 = sympy.sin(Q)+sympy.cos(Q)
u = sympy.atan(r1*sympy.diff(r2,Q,1))
Q = math.pi/4
u = u.evalf()
print "The angle at point of intersection in radians is : "
print u
Angle of intersection
point of intersection of r=sint+cost and r=2 sint is t=pi/4
tanu=dQ/dr∗r
The angle at point of intersection in radians is : 
atan(2*(-sin(Q) + cos(Q))*sin(Q))

Example 4.41, page no. 170

In [41]:
import sympy,math

print "tanu=dQ/dr∗r"
Q = sympy.Symbol('Q')
a = sympy.Symbol('a')
r = 2*a/(1-sympy.cos(Q))
u = sympy.atan(r/sympy.diff(r2,Q,1))
u = u.evalf()
print u
p = r*sympy.sin(u)
r = sympy.Symbol('r')
Q = sympy.acos(1-2*a/r)
p = p.evalf()
print p
tanu=dQ/dr∗r
atan(2*a/((-sin(Q) + cos(Q))*(-cos(Q) + 1)))
4.0*a**2*(4.0*a**2/((-sin(Q) + cos(Q))**2*(-cos(Q) + 1.0)**2) + 1.0)**(-0.5)/((-sin(Q) + cos(Q))*(-cos(Q) + 1.0)**2)

Example 4.43, page no. 172

In [19]:
import numpy,sympy,math

a = sympy.Symbol('a')
t = sympy.Symbol('t')
x = a*(t+sympy.sin(t))
y = a*(1-sympy.cos(t))
s2 = sympy.diff(y,t,2)/sympy.diff(x,t,2)
s1 = sympy.diff(y,t,1)/sympy.diff(x,t,1)
r = (1+s1**2)**(3/2)/s2
print "The radius of curvature is :",r
The radius of curvature is : -(1 + sin(t)**2/(cos(t) + 1)**2)*sin(t)/cos(t)

Example 4.46, page no. 176

In [42]:
import numpy,sympy,math

print "radius of curvature"
a = sympy.Symbol('a')
t = sympy.Symbol('t')
r = a*(1-sympy.cos(t))
r1 = sympy.diff(r,t,1) 
l = (r**2+r1**2)**(3/2)/(r**2+2*r1**2-r*r1)
r = sympy.Symbol('r')
t = sympy.acos(1-r/a)
l = l.evalf()
print l
print "Which is proportional to rˆ0.5"
radius of curvature
(a**2*(-cos(t) + 1.0)**2 + a**2*sin(t)**2)/(a**2*(-cos(t) + 1.0)**2 - a**2*(-cos(t) + 1.0)*sin(t) + 2.0*a**2*sin(t)**2)
Which is proportional to rˆ0.5

Example 4.47, page no. 177

In [21]:
import numpy,sympy,math

print "The centre of curvature"
x = sympy.Symbol('x')
a = sympy.Symbol('a')
y = sympy.Symbol('y')
y = 2*(a*x)**0.5
y1 = sympy.diff(y,x,1)
y2 = sympy.diff(y,x,2)
xx = x-y1*(1+y1)**2/y2
yy = y+(1+y1**2)/y2
print "the coordinates x,y are resp : "
print xx
print yy
The centre of curvature
the coordinates x,y are resp : 
2.0*x*(1 + 1.0*(a*x)**0.5/x)**2 + x
-2.0*x**2*(a*x)**(-0.5)*(1 + 1.0*(a*x)**1.0/x**2) + 2*(a*x)**0.5

Examle 4.48, page no. 177

In [22]:
import numpy,sympy,math

print "centre of curvature of given cycloid"
a = sympy.Symbol('a')
t = sympy.Symbol('t')
x = a*(t-sympy.sin(t))
y = a*(1-sympy.cos(t))
y1 = sympy.diff(y,t,1)
y2 = sympy.diff(y,t,2)
xx = x-y1*(1+y1)**2/y2 
yy = y+(1+y1**2)/y2
print "the coordinates x,y are resp : "
print xx
print yy
print "which another parametric equation of cycloid"
centre of curvature of given cycloid
the coordinates x,y are resp : 
a*(t - sin(t)) - (a*sin(t) + 1)**2*sin(t)/cos(t)
a*(-cos(t) + 1) + (a**2*sin(t)**2 + 1)/(a*cos(t))
which another parametric equation of cycloid

Example 4.52, page no. 180

In [42]:
import sympy
print 'To find the maxima and minima of given function put f1(x)=0'
x = sympy.Symbol('x')
f=3*x**4-2*x**3-6*x**2+6*x+1
k = sympy.diff(f,x)
x = sympy.poly(0,x)
k = sympy.solve(k)
print k
To find the maxima and minima of given function put f1(x)=0
[-1, 1/2, 1]

Example 4.61, page no. 188

In [49]:
import numpy,sympy,math

print "to find the assymptote of given curve"
x = sympy.Symbol('x')
y = sympy.Symbol('y')
f = x**2*y**2-x**2*y-x*y**2+x+y+1
f1 = sympy.poly(f,y,x)
f1 = f1.coeffs()
print "assymptotes parallel to x−axis is given by f1=0 where f1 is : "
print sympy.factor(f1)
f2 = sympy.poly(f,y,x)
print "assymptotes parallel to y−axis is given by f 2=0 and f2 is : "
print sympy.factor(f2)
to find the assymptote of given curve
assymptotes parallel to x−axis is given by f1=0 where f1 is : 
[1, -1, -1, 1, 1, 1]
assymptotes parallel to y−axis is given by f 2=0 and f2 is : 
x**2*y**2 - x**2*y - x*y**2 + x + y + 1