【发布时间】:2018-08-19 18:28:36
【问题描述】:
编辑: 一切都很好:)
This is a code which works with small values of t=20 and TR=([[30,20,12,23..],[...]]) but when I put higher values it is shown "Expect x to be a 1-D sorted array_like.". Do you know how to solve this problem??
import matplotlib.pylab as plt
from scipy.special import erfc
from scipy import sqrt
from scipy import exp
import numpy as np
from scipy.interpolate import interp1d
# The function to inverse:
t = 100
alfa = 1.1*10**(-7)
k = 0.18
T1 = 20
Tpow = 180
def F(h):
p = erfc(h*sqrt(alfa*t)/k)
return T1 + (Tpow-T1)*(1-exp((h**2*alfa*t)/k**2)*(p))
# Interpolation
h_eval = np.linspace(-80, 500, 200) # critical step: define the discretization grid
F_inverse = interp1d( F(h_eval), h_eval, kind='cubic', bounds_error=True )
# Some random data:
TR = np.array([[130, 100, 130, 130, 130],
[ 90, 101, 100, 120, 90],
[130, 130, 100, 100, 130],
[120, 101, 120, 90, 110],
[110, 130, 130, 110, 130]])
# Compute the array h for a given array TR
h = F_inverse(TR)
print(h)
# Graph to verify the interpolation
plt.plot(h_eval, F(h_eval), '.-', label='discretized F(h)');
plt.plot(h.ravel(), TR.ravel(), 'or', label='interpolated values')
plt.xlabel('h'); plt.ylabel('F(h) or TR'); plt.legend();
有谁知道如何在 numpy 中求解非线性隐式方程。 我的等式中包含数组 TR 和其他值。
我需要解决它 - 结果收到一个形状相同的新数组
【问题讨论】:
-
F(h)在做什么?您面临的具体问题是什么? -
我有方程:0=TR+(Tpow-T1)*(1-np.exp(h2*alfat/k2 )+2/(3*np.sqrt(3))*h3*(alfat)**(3/2)/k3) 其中 h 是我的未知值。我想找到那个方程的解。 (考虑到 TR 是一个数组)提前谢谢
标签: python arrays numpy scipy nonlinear-optimization