- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
所以我试图将一组数据点拟合到这个方程:
abs(I) = Io(exp((qV)/(nKT)) - 1) --- 肖克利二极管方程
我得到了一堆数据点。知道 V 和 I 值后,我需要优化 Io 和 n 值,以获得与给定数据集紧密匹配的数据。
但是,scipy 优化曲线拟合并没有给我想要的值,即 n = ~1.15 和 Io = ~1.8E-13,而是给我 n = 2.12 和 I = 2.11E-11。我怀疑这是由于数据集值非常小,扰乱了优化,但即使我将初始猜测设置为 n = 1.15 和 Io = 1.8E-13,优化值也不会改变。
有人知道如何解决这个问题吗?
import numpy as np
import math
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
Voltage = np.array([-0.5 , -0.49, -0.48, -0.47, -0.46, -0.45, -0.44, -0.43, -0.42,
-0.41, -0.4 , -0.39, -0.38, -0.37, -0.36, -0.35, -0.34, -0.33,
-0.32, -0.31, -0.3 , -0.29, -0.28, -0.27, -0.26, -0.25, -0.24,
-0.23, -0.22, -0.21, -0.2 , -0.19, -0.18, -0.17, -0.16, -0.15,
-0.14, -0.13, -0.12, -0.11, -0.1 , -0.09, -0.08, -0.07, -0.06,
-0.05, -0.04, -0.03, -0.02, -0.01, 0. , 0.01, 0.02, 0.03,
0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 , 0.11, 0.12,
0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2 , 0.21,
0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3 ,
0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4 ])
Current = np.array([ 6.99000000e-13, 6.83000000e-13, 6.57000000e-13,
6.46000000e-13, 6.19000000e-13, 6.07000000e-13,
5.86000000e-13, 5.73000000e-13, 5.55000000e-13,
5.37000000e-13, 5.27000000e-13, 5.08000000e-13,
4.92000000e-13, 4.75000000e-13, 4.61000000e-13,
4.43000000e-13, 4.32000000e-13, 4.18000000e-13,
3.99000000e-13, 3.91000000e-13, 3.79000000e-13,
3.66000000e-13, 3.54000000e-13, 3.43000000e-13,
3.34000000e-13, 3.18000000e-13, 3.06000000e-13,
2.96000000e-13, 2.86000000e-13, 2.77000000e-13,
2.66000000e-13, 2.59000000e-13, 2.54000000e-13,
2.43000000e-13, 2.33000000e-13, 2.22000000e-13,
2.16000000e-13, 2.07000000e-13, 2.00000000e-13,
1.94000000e-13, 1.85000000e-13, 1.77000000e-13,
1.68000000e-13, 1.58000000e-13, 1.48000000e-13,
1.35000000e-13, 1.21000000e-13, 1.03000000e-13,
7.53000000e-14, 4.32000000e-14, 2.33000000e-15,
6.46000000e-14, 1.57000000e-13, 2.82000000e-13,
4.58000000e-13, 7.07000000e-13, 1.06000000e-12,
1.57000000e-12, 2.28000000e-12, 3.29000000e-12,
4.75000000e-12, 6.80000000e-12, 9.76000000e-12,
1.39000000e-11, 1.82000000e-11, 2.57000000e-11,
3.67000000e-11, 5.21000000e-11, 7.39000000e-11,
1.04000000e-10, 1.62000000e-10, 2.27000000e-10,
3.21000000e-10, 4.48000000e-10, 6.21000000e-10,
8.70000000e-10, 1.20000000e-09, 1.66000000e-09,
2.27000000e-09, 3.08000000e-09, 4.13000000e-09,
5.46000000e-09, 7.05000000e-09, 8.85000000e-09,
1.11000000e-08, 1.39000000e-08, 1.74000000e-08,
2.05000000e-08, 2.28000000e-08, 2.52000000e-08,
2.91000000e-08])
def diode_function(V, n, Io):
kt = 300 * 1.38 * math.pow(10, -23)
q = 1.60 * math.pow(10, -19)
I_final = Io * (np.exp( (q * V) / (n * kt) ) - 1)
return abs(I_final)
p0 = [1.15, 1.8e-13]
popt, pcov = curve_fit(diode_function, Voltage, Current, p0 = p0)
print(popt)
fig = plt.figure()
ax = fig.add_subplot(121)
ax.set_title('I_d vs V_d')
ax.set_xlabel('V_d')
ax.set_ylabel('I_d')
ax.set_yscale('log')
plt.plot(Voltage, Current, 'ko', label="Original Data")
plt.plot(Voltage, diode_function(Voltage, *popt), 'r-', label="Fitted Curve")
plt.legend(loc='best')
ax = fig.add_subplot(122)
ax.set_title('I_d vs V_d')
ax.set_xlabel('V_d')
ax.set_ylabel('I_d')
ax.set_yscale('log')
popt = [1.15,1.8e-13]
plt.plot(Voltage, Current, 'ko', label="Original Data")
plt.plot(Voltage, diode_function(Voltage, *popt), 'r-', label="Fitted Curve")
plt.legend(loc='best')
plt.show()
左图是经过scipy优化的,右图是我想要的
最佳答案
我猜你是在正确的轨道上,使用对数来缩放数据,以使差异小得多。为了防止对数出现问题,一种常见的选择是添加一个常数。我们可以使用 log(x+constant)
来代替 log(x)
。该常数需要为 1 或更高。
使用不同的常数仍然会产生不同的结果,同样是因为在最小二乘法中较大的值的权重较高。
# imports and data as in question
def diode_function(V, n, Io):
kt = 300 * 1.38e-23
q = 1.60e-19
I_final = Io * (np.exp( (q * V) / (n * kt) ) - 1)
return np.abs(I_final)
p0 = [1.15, 1.8e-13]
popt, pcov = curve_fit(diode_function, Voltage, Current, p0 = p0)
fig, ax = plt.subplots()
ax.set_title('I_d vs V_d')
ax.set_xlabel('V_d')
ax.set_ylabel('I_d')
ax.set_yscale('log')
ax.plot(Voltage, Current, 'ko', label="Original Data")
offsets = [1,15]
colors = ["limegreen", "crimson"]
for offset, color in zip(offsets,colors):
logdf = lambda V,n,Io: np.log10(diode_function(V, n, Io)+offset)
poptn, pcovn = curve_fit(logdf, Voltage, np.log10(Current+offset), p0 = p0)
ax.plot(Voltage, 10**(logdf(Voltage, *poptn))-offset,
color=color, label="fit (offset: {})".format(offset))
ax.legend(loc='best')
plt.show()
关于python - Scipy 曲线拟合优化不适用于对数刻度值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47148803/
我想在 python 中找出一个整数的 log10,但我得到了一个错误,比如数学域错误 我的代码是这样的w=math.log10(q*q1)/math.log10(2) 其中 q1,q2 是整数 是的
舍入小数 在 NumPy 中,主要有五种方法来舍入小数: 截断 去除小数部分,并返回最接近零的浮点数。使用 trunc() 和 fix() 函数。 示例: import numpy as n
我有一个数值范围为 0 到 100 的 slider 。 我想将它们映射到 100 到 10,000,000 的范围内。 我在网上看到过一些函数,但它们都是用 C++ 编写的。我需要它在 Javasc
我想请用户输入一个整数(N),然后显示他/她输入的整数的 10 对数。我已经成功计算了 10 对数,但不知道如何像下面这样显示它: Write in an Integer: 455666 455666
我将 x 轴设置为对数刻度。最大值为10000,最小值为1。 GraphPane mypane = zedgraphcontrol.GraphPane; mypane.XAxis.Type = Axi
我正在尝试编写一个快速算法来计算 log gamma function 。目前我的实现看起来很幼稚,只是迭代了 1000 万次来计算 gamma 函数的对数(我还使用 numba 来优化代码)。 im
这个问题在这里已经有了答案: How to show minor tick labels on log-scale with Matplotlib (2 个答案) 关闭 7 年前。 将行 plt.y
抱歉标题不好 ;) 我正在尝试重新创建我在其他一些工作中遇到的 matlab 图,但我不太了解他们使用的比例。 y轴增量如下(从上往下[+ve y]): 0.9999,0.999,0.99,0.9,0
由于 1000 的以 10 为底的对数是 3,您可能期望 Math::log(1000, 10) 返回 3。相反,它返回 2.9999999999999996。 这是因为 Ruby 中的 float
我对对数 X 轴有疑问。阈值大于 0,x 的最小值为 1,并且所有 X 值都大于 0。并且仍然给我相同的错误 Can't plot zero or subzero values on a logari
我需要在我的应用程序中实现折线图,我想使用 MPAndroidChart。问题是 y 轴上的值将介于 1 和 1x10^-12 之间。这就是为什么我需要在该轴上的对数 View 。 有没有办法用那个库
我正在尝试按照 Logarithmic slider 中的示例进行操作. 这是我使用的代码: Timeline._MIN_PER_MINUTE = 1; Timeline._MIN_PER_HOUR
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve th
我尝试为对数 y 轴绘制条形图。不幸的是,如果我将 y 轴设置为对数,则不再有条形图。我该怎么做才能实现这一目标?是否可以在 bar-function 中设置引用点(默认似乎为零)? 我的代码是: i
所以我一直在努力掌握 Big Oh 的计算方法。我觉得我已经掌握了基础知识,但对看似非常简单的计算感到困惑。所以如果下面的计算有很大的 O(n log n)(我真的希望我至少做对了)改变循环的顺序对复
我知道二维绘图的 semilogx 和 semilogy。 SURF 和 MESH 有什么等价物吗? 最佳答案 如上述链接所述,要将所有三个轴设置为对数刻度,请使用 set(gca, 'XScale'
这看起来很简单,但我在用 Ruby 计算 log (Base 5) 时遇到了问题。 显然标准的 base-10 日志工作正常: >> value = Math::log(234504) => 12.3
这段代码是用 C 语言根据 pollard 的对数 rho 算法(来自 wiki)编写的。在此代码中,如果我输入 alpha=2、beta=5、N=1019,则必须返回 a=681、b=378、A=3
有了this question之后通过指向 an external site 的链接回答,我意识到我解决了一个问题,只是为了得到另一个问题:在对数刻度上,MESH 和 SURF 函数的 C=Z 参数不
我正在尝试解决 the SPOJ problem PGCD , 它询问最大公约数表中出现了多少个素数。 我想到的第一个想法是先通过筛分生成素数。 然后,对于每个素数 p,查看有多少对(a,b),其中
我是一名优秀的程序员,十分优秀!