简体   繁体   English

Python:在渐近区域附近求解

[英]Python: fsolve near asymptotic region

For E=0.46732451 and t=1.07589765 I am trying to solve for the upper limit of the integral t= \\int_{0}^{z} 1/sqrt(2*(0.46732451-z**2)), I plotted this function and it looks like this 对于E=0.46732451t=1.07589765我试图求解积分t = \\ int_ {0} ^ {z} 1 / sqrt(2 *(0.46732451-z ** 2))的上限,我对此进行了绘制功能,看起来像这样 相对于 .

Around t=1 it kind of asymptotes. t=1左右逐渐渐近。

I have the following code 我有以下代码

import numpy as np
from scipy import integrate
from scipy.optimize import fsolve

def fg(z_up,t,E):
      def h(z,E):
           return 1/(np.sqrt(2*(E-z**2)))

      b, err = integrate.quad(h, 0, z_up,args=(E)) 
      return b-t 



x0 = 0.1
print fsolve(fg, x0, args=(1.07589765, 0.46732451))[0]

But this code just outputs the guess value, no matter what I put, so I am guessing it has something to do with the fact that the curve asymptotes there. 但是,无论我输入什么内容,此代码都只会输出猜测值,因此我猜测它与那里的曲线渐近有关。 I should note that this code works for other values of t which are away from the asymptotic region. 我应该注意,此代码适用于t其他值,这些值远离渐近区域。

Can anyone help me resolve this? 谁能帮我解决这个问题?

Thanks 谢谢

EDIT After playing around for a while, I solved the problem, but it's kind of a patchwork, it only works for similar problems not in general (or does it?) 编辑玩了一会儿之后,我解决了这个问题,但这有点像是拼凑而成,它只适用于一般情况下的类似问题(不是吗?)

I made the following changes: the maximum value that z can attain is sqrt(0.46732451) , so I set x0=0.5*np.sqrt(0.46732451) and set factor anywhere between 0.1 to 1 , and out pops the correct answer. 我进行了如下修改:使最大值z能达到是sqrt(0.46732451)所以设置x0=0.5*np.sqrt(0.46732451)并设置factor之间的任何地方0.11 ,取出这个正确的答案。 I don't have an explanation for this, perhaps someone who is an expert in this matter can help? 我对此没有任何解释,也许有人在这方面是专家可以提供帮助吗?

You should use bisect instead, as it handles nan without problems: 您应该改用bisect ,因为它可以毫无问题地处理nan

print bisect(fg, 0.4, 0.7, args=(1.07589765, 0.46732451))

Here 0.4 and 0.7 are taken as an example but you can generalize this for almost any diverging integral by using 0 and let's say 1e12 as the limits. 这里以0.4和0.7为例,但是您可以使用0并以1e12作为极限值,将其推广到几乎所有发散积分。

However, I'm not sure I understand what you really want to do... if you want to find the limit at which the integral diverges, cf. 但是,我不确定我是否真正了解您要做什么...如果您想找到积分发散的极限,请参见。 your 你的

I am trying to solve for the upper limit of the integral 我正在尝试求解积分的上限

then it's simply for z_up -> \\sqrt{E} \\approx 0,683611374 ... So to find the (approximate) numerical value of the integral you just have to decrease z_up from that value until quad stops giving a nan ... 那么它仅适用于z_up -> \\sqrt{E} \\approx 0,683611374 ...因此,要找到积分的(近似)数值,您只需要从该值中z_up ,直到quad不再给出nan ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM