【问题标题】:Using scipy's newton function to solve an equation使用 scipy 的牛顿函数求解方程
【发布时间】:2020-09-17 00:57:12
【问题描述】:

几个月来,我一直在使用 scipy 的“牛顿”函数,但遇到了一个相当混乱的情况。我的一个情节,涉及以下代码:

#Declaring frequency and wave vector arrays
w_array = np.linspace(0.1,3,1000)*10**15
k_array = np.array([])

#Declaring variables
p = 2.85*10**15
e1=1
c=300000000

def twolayer(k):
    e2 = 3.43-(p**2)/(w**2 - (1j*gamma*w))
    result = ((w/c)*(((e2*e1)/(e2+e1))**0.5))-k
    return result

#Loop that uses secant method for each value of omega to find solutions for k
for w in w_array:
    gamma = 2.23 * 10**14
    k_array = np.append(k_array,newton(twolayer,0))

print(twolayer(0))

#Plotting
plt.figure(dpi=100)
plt.scatter(k_array.real,w_array)
plt.xlabel('Wave vector k')
plt.ylabel('Frequency ω')

输出如下图:

但我有点困惑'newton' 函数在这里实际上在做什么。由于我没有提供导数,因此它采用 Secant 方法,但是什么过程允许它解决给定 x 值具有多个 y 值的函数?

【问题讨论】:

    标签: python matplotlib math scipy


    【解决方案1】:

    你只是想错了!在您的计算中,k 是w 的函数。

    试试:

    #Plotting
    plt.figure(dpi=100)
    plt.scatter(w_array, k_array.real)
    plt.xlabel('Frequency ω')
    plt.ylabel('Wave vector k')
    

    给予

    【讨论】:

      猜你喜欢
      • 2017-05-05
      • 1970-01-01
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      • 2018-02-26
      • 2021-12-09
      • 1970-01-01
      • 2018-01-03
      相关资源
      最近更新 更多