Here, I would like to write about multiple integrals using Python.
python
from sympy import *
x = symbols('x')
y = symbols('y')
f = x**2 + y**2 + 1
integrate(f,(x, 0, 1),(y,0,1))
By the way
python
x = symbols('x')
y = symbols('y')
Part is
python
x = Symbol('x')
y = Symbol('y')
Or
python
x,y = symbols('x y')
But it's okay.
You can also draw a curved surface with z = f by writing as follows.
python
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
x = y = np.linspace(-5,5)
X,Y = np.meshgrid(x,y)
f = X**2 + Y**2 + 1
fig = plt.figure(figsize = (10,10))
ax = fig.add_subplot(1,1,1,projection="3d")
ax.plot_surface(X, Y, f)
python
from sympy import *
x = symbols('x')
y = symbols('y')
f = x**2 + x*y*2 + 1
#Integrate from the variables written on the left.
integrate(f,( x, 0, 2-y),(y, 0, 2))
python
from sympy import *
x = symbols('x')
y = symbols('y')
f = x**2 + y**2 + 1
#Writing the integration region as an inequality does not work.
integrate(f,(x, 0, sqrt(1-y**2)),(y,0,1))
python
\vec{r}(u,v) = ( \cos u, \sin u, v)\\
D:0 \leq u \leq \pi,~~0 \leq v \leq 1\\
Scalar field in~f=\sqrt{x^2+y^2+z^2}Find the value for the surface integral of.
python
from sympy import *
u = symbols('u')
v = symbols('v')
r =Matrix([ cos(u), sin(u), v])
A = [0]*3
A[0] = diff(r,u)[0]
A[1] = diff(r,u)[1]
A[2] = diff(r,u)[2]
B = [0]*3
B[0] = diff(r,v)[0]
B[1] = diff(r,v)[1]
B[2] = diff(r,v)[2]
C = np.cross(A,B)
print(C)
#Therefore, the length of the outer product of A and B is 1.
#python is cos(u)**2+sin(u)**2=You can't use 1, so you can transform the formula yourself.
f = sqrt(1+r[2]**2)
integrate(f,(v, 0, 1),(u,0,pi))
Recommended Posts