【问题标题】:Calculating rate of decay of a material in python在python中计算材料的衰减率
【发布时间】:2020-01-01 05:41:50
【问题描述】:

我必须计算材料衰变的速率。我在 5 年内对材料进行了 5 次测量。以下是我的方法:-

我使用蒙特卡罗方法将初始不确定性和测试不确定性添加为噪声。

最初我假设速率是线性的,使用 np.linalg.lstsq 我计算了速率,基本上是线的斜率。

现在我想计算速率假设速率是加速曲线,当材料损失更多时衰减更多。

这有点像:-

np.random.seed(0)

x_data = np.linspace(0, 5, num=50).reshape(-1,1)

# function something in the form of y = variable^x, taking variable value as 
#1.1 below
var = 1.1
y_data = np.power(var, x_data)

plt.figure(figsize=(6, 4))
plt.scatter(x_data, y_data)
plt.show()

我查看了 np.polyfit 和 curve_fit 选项,仍在试图找出计算速率。

【问题讨论】:

  • 汇率很可能是 A*exp(x/b) 形式的指数函数,其中 b 是您的汇率。尝试用曲线拟合来拟合它。

标签: python scipy statistics


【解决方案1】:

使用 scipy.optimize 中的 curve_fit 方法。一个合适的拟合模型是指数衰减函数;然而,curve_fit 方法将估计任何函数的参数。

from scipy.optimize import curve_fit
import numpy as np
from matplotlib import pyplot

def decay(t,b,c):
    # A = initial amount
    # B = decay constant
    # t = time
    # C = additive constant
    x0 = 100
    return x0 * np.exp(-b * t) + c


t1 = [10,20,70,100,110] # experimental time data
y1 = [80,75,78,44,46] # experimental final amount data

# use curve_fit to estimate B (decay paramter) and C (additive paramter)
params = curve_fit(decay,t1, y1)

pyplot.plot(t1,y1) # actual
pyplot.plot(t1,[decay(i,*params) for i in t1]) # predicted

pyplot.show()

print(params)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    • 2021-09-27
    相关资源
    最近更新 更多