Big integration error with integrate.nquad

家住魔仙堡 提交于 2019-12-30 07:49:20

问题


Firstly, I integrate a simple function on an ellipse. Secondly, I integrate the same function to which I add a constant value. The results are not consistent as you can see on the bottom of my message.

Thanks in advance for you help.

# -*- coding: utf-8 -*-
from scipy import integrate
from math import *

a = 2.0;
b = 1.0;
Cst = 1.0

def f1(x, y):
    return sqrt(abs(1. -(x/a)**2 -(y/b)**2)) 

def f2(x, y):
    return sqrt(abs(1. -(x/a)**2 -(y/b)**2)) + Cst

def un(x, y):
   return 1.0

def bounds_y():
    return [-b, b]

def bounds_x(y):
    xLimSup = a*sqrt(1-(y/b)**2)
    xLimInf = -xLimSup    
    return [xLimInf, xLimSup]

[S, err] = integrate.nquad(un, [bounds_x, bounds_y])
Stheo = a*b*pi  

[Intf1, err1] = integrate.nquad(f1, [bounds_x, bounds_y]) 
Intf1corr = Intf1 + Cst * S

[Intf2, err2] = integrate.nquad(f2, [bounds_x, bounds_y]) 

print("S     =     %1.4e " % S)
print("Stheo =     %1.4e \n" % Stheo)
print("Intf1 =     %1.4e " % Intf1)
print("Intf1corr = %1.4e " % Intf1corr)
print("Intf2 =     %1.4e " % Intf2) # Ce résultat est complètement faux !!!

**********************************************************

S     =     6.2832e+00
Stheo =     6.2832e+00 

Intf1 =     4.1888e+00 
Intf1corr = 1.0472e+01 
Intf2 =     9.7238e-01 

来源:https://stackoverflow.com/questions/27270044/big-integration-error-with-integrate-nquad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!