Python code only Please answer the question using Python cod
Python code only!!
Please answer the question using Python code only!!
Slove problem 21.15
2. Problem 21.15. Before solving this problem study the example 21.9 in the textbook; to obtain analytical solution, first integrate over x from -3 to 1, then over y from 0 to 2, and finally over z from -2 to 2. Compute relative error usingl the difference between analytical and numerical solutions.Solution
#Solving left side integration of x^3 dxdydz
 F1 = 1 #setting initial value
#first integration Integration of x^3dx
 b = 1
 a = -3
 F1 *= (b-a)/6.0*(a**3 + 4.0*(a**3+b**3)/2.0 + b**3)
#second integration dy
 b = 2
 a = 0
 F1 *= (b-a)/6.0*(1.0 + 4.0*(1.0+1.0)/2.0 + 1)
#third integration dz
 b = 2
 a = -2
 F1 *= (b-a)/6.0*(1.0 + 4.0*(1.0+1.0)/2.0 + 1.0)
 print F1
 #Solving right side integration -3yz dxdydz
 F2 = -3
#first integration dx
 b = 1
 a = -3
 F2 *= (b-a)/6.0*(1.0 + 4.0*(1.0+1.0)/2.0 + 1.0)
#second integration ydy
 b = 2
 a = 0
 F2 *= (b-a)/6.0*(b + 4.0*(a+b)/2.0 + b)
#third integration zdz
 b = 2
 a = -2
 F2 *= (b-a)/6.0*(b + 4.0*(a+b)/2.0 + b)
integration = F1+F2
 print integration
 integration_analytical = -160
 relative_error = abs(integration - integration_analytical)/integration_analytical*100.0
 print relative_error

