# Chapter 5 : Partial Differentiation And Its Applications¶

## Example 5.5, page no. 195¶

In [1]:
import sympy

x = sympy.Symbol('x')
y = sympy.Symbol('y')
z = sympy.Symbol('z')
v = (x**2+y**2+z**2)**(-1/2)
a = sympy.diff(v,x,2)
b = sympy.diff(v,y,2)
c = sympy.diff(v,z,2)
print a+b+c

2*(4*x**2/(x**2 + y**2 + z**2) - 1)/(x**2 + y**2 + z**2)**2 + 2*(4*y**2/(x**2 + y**2 + z**2) - 1)/(x**2 + y**2 + z**2)**2 + 2*(4*z**2/(x**2 + y**2 + z**2) - 1)/(x**2 + y**2 + z**2)**2


## Example 5.14, page no. 203¶

In [2]:
import sympy

x = sympy.Symbol('x')
y = sympy.Symbol('y')
u = sympy.asin((x+y)/(x**0.5+y**0.5))
a = sympy.diff(u,x)
b = sympy.diff(u,y)
c = sympy.diff(a,x)
d = sympy.diff(b,y)
e = sympy.diff(b,x)
print x*a+y*b
print (1/2)*sympy.tan(u)
print (x**2)*c+2*x*y*e+(y**2)*d
print (-sympy.sin(u)*sympy.cos(2*u))/(4*(sympy.cos(u))**3)

x*(-0.5*x**(-0.5)*(x + y)/(x**0.5 + y**0.5)**2 + 1/(x**0.5 + y**0.5))/sqrt(1 - (x + y)**2/(x**0.5 + y**0.5)**2) + y*(-0.5*y**(-0.5)*(x + y)/(x**0.5 + y**0.5)**2 + 1/(x**0.5 + y**0.5))/sqrt(1 - (x + y)**2/(x**0.5 + y**0.5)**2)
0
x**2*((0.25*x**(-1.5)*(x + y)/(x**0.5 + y**0.5)**2 + 0.5*x**(-1.0)*(x + y)/(x**0.5 + y**0.5)**3 - 1.0*x**(-0.5)/(x**0.5 + y**0.5)**2)/sqrt(1 - (x + y)**2/(x**0.5 + y**0.5)**2) + (-0.5*x**(-0.5)*(x + y)**2/(x**0.5 + y**0.5)**3 + (2*x + 2*y)/(2*(x**0.5 + y**0.5)**2))*(-0.5*x**(-0.5)*(x + y)/(x**0.5 + y**0.5)**2 + 1/(x**0.5 + y**0.5))/(1 - (x + y)**2/(x**0.5 + y**0.5)**2)**(3/2)) + 2*x*y*((0.5*x**(-0.5)*y**(-0.5)*(x + y)/(x**0.5 + y**0.5)**3 - 0.5*x**(-0.5)/(x**0.5 + y**0.5)**2 - 0.5*y**(-0.5)/(x**0.5 + y**0.5)**2)/sqrt(1 - (x + y)**2/(x**0.5 + y**0.5)**2) + (-0.5*x**(-0.5)*(x + y)**2/(x**0.5 + y**0.5)**3 + (2*x + 2*y)/(2*(x**0.5 + y**0.5)**2))*(-0.5*y**(-0.5)*(x + y)/(x**0.5 + y**0.5)**2 + 1/(x**0.5 + y**0.5))/(1 - (x + y)**2/(x**0.5 + y**0.5)**2)**(3/2)) + y**2*((0.25*y**(-1.5)*(x + y)/(x**0.5 + y**0.5)**2 + 0.5*y**(-1.0)*(x + y)/(x**0.5 + y**0.5)**3 - 1.0*y**(-0.5)/(x**0.5 + y**0.5)**2)/sqrt(1 - (x + y)**2/(x**0.5 + y**0.5)**2) + (-0.5*y**(-0.5)*(x + y)**2/(x**0.5 + y**0.5)**3 + (2*x + 2*y)/(2*(x**0.5 + y**0.5)**2))*(-0.5*y**(-0.5)*(x + y)/(x**0.5 + y**0.5)**2 + 1/(x**0.5 + y**0.5))/(1 - (x + y)**2/(x**0.5 + y**0.5)**2)**(3/2))
-(x + y)*cos(2*asin((x + y)/(x**0.5 + y**0.5)))/(4*(1 - (x + y)**2/(x**0.5 + y**0.5)**2)**(3/2)*(x**0.5 + y**0.5))


## Example 5.25.1, page no. 204¶

In [15]:
import sympy

r = sympy.Symbol('r')
l = sympy.Symbol('l')
x = r*sympy.cos(l)
y = r*sympy.sin(l)
a = sympy.diff(x,r)
b = sympy.diff(x,l)
c = sympy.diff(y,r)
d = sympy.diff(y,l)
A = sympy.Matrix([[a,b],[c,d]])
print A.det()

r*sin(l)**2 + r*cos(l)**2


## Example 5.25.2, page no. 204¶

In [16]:
import sympy

r = sympy.Symbol('r')
l = sympy.Symbol('l')
z = sympy.Symbol('z')
x = r*sympy.cos(l)
y = r*sympy.sin(l)
m = z
a = sympy.diff(x,r)
b = sympy.diff(x,l)
c = sympy.diff(x,z)
d = sympy.diff(y,r)
e = sympy.diff(y,l)
f = sympy.diff(y,z)
g = sympy.diff(m,r)
h = sympy.diff(m,l)
i = sympy.diff(m,z)
A = sympy.Matrix([[a,b,c],[d,e,f],[g,h,i]])
print A.det()

r*sin(l)**2 + r*cos(l)**2


## Example 5.25.3, page no. 205¶

In [25]:
import sympy,numpy

r = sympy.Symbol('r')
l = sympy.Symbol('l')
m = sympy.Symbol('m')
x = r*sympy.cos(l)*sympy.sin(m)
y = r*sympy.sin(l)*sympy.sin(m)
z = r*sympy.cos(m)
a = sympy.diff(x,r)
b = sympy.diff(x,m)
c = sympy.diff(x,l)
d = sympy.diff(y,r)
e = sympy.diff(y,m)
f = sympy.diff(y,l)
g = sympy.diff(z,r)
h = sympy.diff(z,m)
i = sympy.diff(z,l)
A = sympy.Matrix([[a,b,c],[d,e,f],[g,h,i]])
print A.det()

r**2*sin(l)**2*sin(m)**3 + r**2*sin(l)**2*sin(m)*cos(m)**2 + r**2*sin(m)**3*cos(l)**2 + r**2*sin(m)*cos(l)**2*cos(m)**2


## Example 5.26, page no. 206¶

In [22]:
import numpy,sympy

x1 = sympy.Symbol('x1')
x2 = sympy.Symbol('x2')
x3 = sympy.Symbol('x3')
y1 =(x2*x3)/x1
y2 =(x3*x1)/x2
y3 =(x1*x2)/x3
a = sympy.diff(y1,x1)
b = sympy.diff(y1,x2)
c = sympy.diff(y1,x3)
d = sympy.diff(y2,x1)
e = sympy.diff(y2,x2)
f = sympy.diff(y2,x3)
g = sympy.diff(y3,x1)
h = sympy.diff(y3,x2)
i = sympy.diff(y3,x3)
A = sympy.Matrix([[a,b,c],[d,e,f],[g,h,i]])
print A.det()

4


## Example 5.30, page no. 210¶

In [18]:
import sympy,numpy

x = sympy.Symbol('x')
y = sympy.Symbol('y')
u = x*(1-y**2)**0.5+y*(1-x**2)**0.5
v = sympy.asin(x)+sympy.asin(y)
a = sympy.diff(u,x)
b = sympy.diff(u,y)
c = sympy.diff(v,x)
d = sympy.diff(v,y)
A = sympy.Matrix([[a,b],[c,d]])
print A.det()

-1.0*x*y*(-x**2 + 1)**(-0.5)/sqrt(-y**2 + 1) + 1.0*x*y*(-y**2 + 1)**(-0.5)/sqrt(-x**2 + 1)