English 中文(简体)
解决不适当的整体问题,而不考虑
原标题:Solving improper integral without approximating
  • 时间:2015-06-11 01:07:44
  •  标签:
  • python
  • scipy

I m having trouble solving this integral in python. The function being integrated is not defined on the boundaries of integration. I ve found a few more questions similar to this, but all were very specific replies to the issue in particular. I don t want to approximate the integral too much, if possible not at all, as the reason I m doing this integral in the first place is to avoid an approximation. Is there any way to solve this integral?

import numpy as np
from pylab import *
import scipy
from math import *
from scipy import integrate

m_Earth_air = (28.0134*0.78084)+(31.9988*0.209476)+(39.948*0.00934)+(44.00995*0.000314)+(20.183*0.00001818)+(4.0026*0.00000524)+(83.80*0.00000114)+(131.30*0.000000087)+(16.04303*0.000002)+(2.01594*0.0000005)
Tb0 = 288.15
Lb0 = -6.5
Hb0 = 0.0
def Tm_0(z):
    return Tb0+Lb0*(z-Hb0)
k = 1.38*10**-19 #cm^2.kg/s^2.K   #Boltzmann cst
mp = 1.67262177*10**-27 #kg
Rad= 637100000.0 #radius planet #cm
g0 = 980.665 #cm/s^2
def g(z):
    return (g0*((Rad/(Rad+z))**2.0))
def scale_height0(z):
    return k*Tm_0(z*10**-5)/(m_Earth_air*mp*g(z))



def functionz(z,zvar):
    return np.exp(-zvar/scale_height0(z))*((Rad+zvar)/(Rad+z))/((np.sqrt(((Rad+zvar)/(Rad+z))**2.0-1.0)))

def chapman0(z):
    return (1.0/(scale_height0(z)))*((integrate.quad(lambda zvar: functionz(z,zvar), z, np.inf))[0])

print chapman0(1000000)
print chapman0(5000000)

The first block of variables and definitions are fine. The issue is in the "functionz(z,zvar)" and its integration. Any help very much appreciated !

最佳回答

它常常通过调整变量,帮助消除可能的数字不稳定性。 在你的情况下,<代码>zvar从1e6开始,这可能由于<代码>quad(>的某些执行细节而造成问题。 如果您将其排列为y = zvar /z,从而使整合从1开始,则似乎对z = 1e6来说相当好:

def functiony(z, y):
    return np.exp(-y*z/scale_height0(z))*(Rad+y*z)/(Rad+z) / np.sqrt(((Rad+y*z)/(Rad+z))**2.0-1.0)

def chapman0y(z):
    return (1.0/(scale_height0(z)))*((integrate.quad(lambda y: functiony(z,y), 1, np.inf))[0])

>>> print(chapman0y(1000000))

1.6217257661844094e-06

(I set m_ Earth_air = 28.8e-3——这一不变值在您的代码中缺失,我假定其为空气体质(edit/千克/分子)。

关于<代码>z = 5e6,pl_hal0(z)为负值,在权宜之计下具有巨大的积极价值,使整体在定义上有所不同。

问题回答

除非你能够以整体分析方式解决,否则就没有办法解决该问题,而不必对其约束进行近似。 这只是一个 Python子问题,而是一个cal子问题,因此,数学课会给你带来如此巨大的痛苦,以显示数字近似。

如果你不希望它有太多的差别,就选择一个小块sil子,其方法会很快。

Edit- Clarity on final statement:

Epsilon - ɛ - 系指通过集成链条体的体积——三角体X——记住,数字近似值法将有机物纳入肝脏并添加到肝脏中,认为这是每一肝脏的 w,越小肝越好。 你可以在数字组合中具体说明这些内容。

一种迅速趋向的方法意味着这种方法能够迅速接近整体的真正价值,每肝脏的近似值很小。 例如,Riemann的总和是一种天花的方法,假设每个肝脏都是一种 rec子,而一种诱杀器把肝的开始和结束与形成一种诱杀虫的线联系起来。 在这2个国家中,诱杀虫类动物通常会更快地聚集在一起,因为它试图在形状中说明变化。 (由于大多数职能都有较好的电梯,因此通常都使用过吗?)

Both of these variables change the computational expense of the calculation. Typically epsilon is the most expensive to change, thus why it is important you choose a good method of approximation (some can differ by an order of magnitude in error for the same epsilon).

所有这一切都取决于你计算出的错误能容忍多少。

我有类似的问题,发现SciPy之四需要你具体说明另一个参数,epsabs=1e-1000,limit=1000 (步骤size limit),epsrel=1_/code> 为我所尝试的一切工作而努力。 页: 1

def chapman0(z):    
    return (1.0/(scale_height0(z)))*((integrate.quad(lambda zvar: functionz(z,zvar), z, np.inf, limit=1000, epsabs=1e-1000, epsrel=1e1))[0])[0])
#results:
0.48529410529321887
-1.276589093231806e+21

种子是绝对错误的容忍,但对于不迅速趋同的整体来说,似乎正在解决这个问题。 就象这个职位那样有类似问题的其他人而言,情况已经很成熟。 其他包裹中的算法比较快,但我在SciPy没有发现。 成果依据的是现行法典(而不是选定的答案)。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...