Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
隆伯格没有';我不能使用python中的函数i_Python - Fatal编程技术网

隆伯格没有';我不能使用python中的函数i

隆伯格没有';我不能使用python中的函数i,python,Python,我的代码有问题。这两个代码可以很好地分开工作,但是如果我合并它们,我会在第111、97、87、105行得到“float objekt is not callable”错误。我不是一个程序员(物理学家),所以我想请你帮忙。我猜想这可能是个愚蠢的错误 下面是代码,如果您需要其他信息,请询问 谢谢 import numpy import matplotlib.pyplot as plt def V_eff(r,m,l): GM = 3.9860042e14 return -GM*m/

我的代码有问题。这两个代码可以很好地分开工作,但是如果我合并它们,我会在第111、97、87、105行得到“float objekt is not callable”错误。我不是一个程序员(物理学家),所以我想请你帮忙。我猜想这可能是个愚蠢的错误

下面是代码,如果您需要其他信息,请询问

谢谢

import numpy 
import matplotlib.pyplot as plt
def V_eff(r,m,l):
    GM = 3.9860042e14
    return -GM*m/r+l**2/(2*m*r**2)

def EminusVeff(r,m,l,E):
    return E-V_eff(r,m,l)

E = -1.2e10
m = 1000
l1 = 68.8e12
l2 = 57.3e12
l3 = 81.35e12
xmin = 1
xmax = 4e7

xdata = numpy.linspace(xmin,xmax,1000)

plt.plot(xdata, -EminusVeff(xdata, 1000, l3, E), label='{0:.3e}'.format(l3))
plt.plot(xdata, -EminusVeff(xdata, 1000, l1, E), label='{0:.3e}'.format(l1))
plt.plot(xdata, -EminusVeff(xdata, 1000, l2, E), label='{0:.3e}'.format(l2))
plt.xlabel("r")
plt.ylabel(r'$V_\mathrm{eff} - E$')
plt.ylim(-0.14e11,0.2e11)
plt.xlim(0.3e7,4e7)
plt.legend(title="L")
plt.hlines(0, xmin, xmax, lw=0.5)

def regulaFalsi(func, x0, x1, args=()):
    epsilon = 1
    maxIterationen = 100
    iterationen = 0
    xArray = numpy.array([])
    y0 = func(x0, *args)
    y1 = func(x1, *args)
    if (y0*y1 > 0):
        return numpy.nan, -1
    if (x0 > x1):
        x2 = x0
        x0 = x1
        x1 = x2
    x2 = (x0*func(x1, *args) - x1*func(x0, *args))/(func(x1, *args) - func(x0, *args))
    xArray = numpy.append(xArray, x1)
    xArray = numpy.append(xArray, x2)
    while (abs(func(x2, *args)) >= epsilon): 
        y0 = func(x0, *args)
        y2 = func(x2, *args)
        if (y0*y2 > 0):
            x0 = x2 
        else:
            x1 = x2 
        x2 = (x0*func(x1, *args) - x1*func(x0, *args))/(func(x1, *args) - func(x0, *args)) 
        iterationen += 1
        if (iterationen > maxIterationen):
            return x2, -1 
        xArray = numpy.append(xArray, x2)
    return xArray[-1], iterationen

def r_min_max_analytisch(m,l,E):
    GM = 3.9860042e14
    p = (GM*m)/(E)
    q = - l**2/(2*E*m)
    r1 = -p/2-numpy.sqrt((p/2)**2 - q)
    r2 = -p/2+numpy.sqrt((p/2)**2 - q)
    if r1 < r2:
        return r1,r2
    else:
        return r2,r1
    
print("l1 analytisch: ", '{0:.0f} {1:.0f}'.format(*r_min_max_analytisch(m,l1,E)))
print("l1 numerisch : ",'{0:.0f}'.format(*regulaFalsi(EminusVeff, 7e6, 8e6, (m,l1,E))), \
      '{0:.0f}'.format(*regulaFalsi(EminusVeff, 2e7, 3e7, (m,l1,E))))

print("l2 analytisch: ", '{0:.0f} {1:.0f}'.format(*r_min_max_analytisch(m,l2,E)))
print("l2 numerisch : ",'{0:.0f}'.format(*regulaFalsi(EminusVeff, 4e6, 9e6, (m,l2,E))), \
      '{0:.0f}'.format(*regulaFalsi(EminusVeff, 2e7, 3e7, (m,l2,E))))

print("l3 analytisch: ", '{0:.0f} {1:.0f}'.format(*r_min_max_analytisch(m,l3,E)))
print("l3 numerisch : ", '{0:.0f}'.format(*regulaFalsi(EminusVeff, 1.6e7, 1.65e7, (m,l3,E))), \
      '{0:.0f}'.format(*regulaFalsi(EminusVeff, 1.65e7, 1.75e7, (m,l3,E))))


def Trapez(f, a, b, n):
    h = (b - a) / n
    x = a
    In = f(a)
    for k in range(1, n):
        x  = x + h
        In += 2*f(x)

    return (In + f(b))*h*0.5

def romberg(f, a, b, p):   
    I = np.zeros((p, p))
    for i in range(0, p):
        I[i, 0] = Trapez(f, a, b, 2**i)
        for j in range(0, i):
            I[i, j+1] = (4**(j+1) * I[i, j] - I[i-1, j]) / (4**(j+1) - 1)

        print(I[i,0:i+1]) 
    return I
    
def func(r):
    phi = 1/(r**2*np.sqrt(((2*m)/l1**2)(EminusVeff(r,m,l1,E))))
    return phi

              
              
p_rows = 10             
I = romberg(func, 7742086, 25474616, p_rows)
solution = I[p_rows-1, p_rows-1]
print(solution) 


导入numpy
将matplotlib.pyplot作为plt导入
def V_eff(r、m、l):
GM=3.9860042e14
返回-GM*m/r+l**2/(2*m*r**2)
def emiusveff(r,m,l,E):
返回E-V_eff(r,m,l)
E=-1.2e10
m=1000
l1=68.8e12
l2=57.3e12
l3=81.35e12
xmin=1
xmax=4e7
扩展数据=numpy.linspace(xmin,xmax,1000)
plt.plot(扩展数据,-emiusveff(扩展数据,1000,l3,E),标签=“{0:.3e}”。格式(l3))
plt.plot(扩展数据,-emiusveff(扩展数据,1000,l1,E),标签=“{0:.3e}”。格式(l1))
plt.plot(扩展数据,-emiusveff(扩展数据,1000,l2,E),标签=“{0:.3e}”。格式(l2))
plt.xlabel(“r”)
plt.ylabel(r'$V\uMathrm{eff}-E$)
plt.ylim(-0.14e11,0.2e11)
plt.xlim(0.3e7,4e7)
plt.图例(title=“L”)
plt.hlines(0,xmin,xmax,lw=0.5)
def regulaFalsi(func,x0,x1,args=()):
ε=1
maxIterationen=100
迭代n=0
xArray=numpy.array([])
y0=func(x0,*args)
y1=func(x1,*args)
如果(y0*y1>0):
返回numpy.nan,-1
如果(x0>x1):
x2=x0
x0=x1
x1=x2
x2=(x0*func(x1,*args)-x1*func(x0,*args))/(func(x1,*args)-func(x0,*args))
xArray=numpy.append(xArray,x1)
xArray=numpy.append(xArray,x2)
而(abs(func(x2,*args))>=epsilon):
y0=func(x0,*args)
y2=func(x2,*args)
如果(y0*y2>0):
x0=x2
其他:
x1=x2
x2=(x0*func(x1,*args)-x1*func(x0,*args))/(func(x1,*args)-func(x0,*args))
迭代n+=1
如果(iterationen>maxIterationen):
返回x2,-1
xArray=numpy.append(xArray,x2)
返回xArray[-1],迭代n
def r_最小值_最大值分析(m、l、E):
GM=3.9860042e14
p=(GM*m)/(E)
q=-l**2/(2*E*m)
r1=-p/2-numpy.sqrt((p/2)**2-q)
r2=-p/2+numpy.sqrt((p/2)**2-q)
如果r1
了解一下您的
函数
方法:

phi = 1 / (r ** 2 * np.sqrt(((2 * m) / l1 ** 2)(EminusVeff(r, m, l1, E))))
#                                             ^^
有两个表达式没有运算符。
这意味着:使用参数emiusveff(r,m,l1,E)调用(结果)
(r**2*np.sqrt(((2*m)/l1**2)


可能您想在这里乘法,因此您必须显式地添加
*

哦,thx!没有看到。不要忘记标记解决问题的答案:)此外,没有愚蠢的错误。下次,请准确描述您所做的事情-您提到两个合并在一起的程序,但我们不知道哪个是哪个。此外,如果您使用行号,请确保将它们包含在代码中,或者更好的是,在代码中用注释标记这些行,如下图所示。