python - Finding the second integral of the 2D array
问题描述
I have the following 2D array:
N = 6
M = np.zeros((N,N))
for i in range(N-1):
for j in range(N-1):
if i==0 or j==0:
M[i,j] = 0
else:
M[i,j] = 1
Basically, it is the array of zeros on the sides and ones in the middle.
I want to calculate the following integral:
So, I use the code below:
dx=dy=d=1
My, Mx = np.gradient(M, d, d)
Lx = 0
p = 1/(M.shape[0]*M.shape[1])
for i in range(N-1):
for j in range(N-1):
Lx += p*math.sqrt(1+(Mx[i,j])**2)*dx*dy
However, the value that I am getting out of the calculations is not the matching the one it should be: My answer: 0.77 Correct answer: 0.98
Is there anything I am doing wrong?
解决方案
推荐阅读
- java - 井字游戏逻辑
- python - 队列中没有项目,但应该有 python 线程
- reactjs - React Navigation 上的自定义选项卡样式
- laravel - laravel 新手。我收到一个错误,我不知道出了什么问题
- slack - 将 slack 字段添加到 Prometheus 警报管理器 slack 通知
- php - 如何在 PHP7 中将对象转换为数组?
- php - 为什么我的 IF 语句无法定义会员级别?
- qt - 使用 vtkImagePlaneWidget 和 vtkPOpenFOAMReader 的问题
- oracle - Oracle 返回语句以使用“select from”源进行插入操作
- powershell - Powershell 语句的含义