简体   繁体   English

在python中拟合曲线-拟合参数

[英]Fitting curve in python - fitting parameters

I am trying to fit a curve to my data in Python, as follows: 我正在尝试使曲线适合Python中的数据,如下所示:

def func(p1,p2,p3,x):
    return p1*((p2-x)/p2)^(-p3)

And I call this function in an other function, and trying to fit: 我在另一个函数中调用此函数,并尝试拟合:

f1 = func(p1,p2,p3,x)
popt, pcov = curve_fit(f1, T, Susceptibility) 

But Python doesn't regard p1,p2,p3 as a fitting parameter, becouse I get this error message: global name 'p1' is not defined 但是Python并未将p1,p2,p3视为合适的参数,因为我收到此错误消息: global name 'p1' is not defined

Read the docs more carefully, x is supposed to be the first parameter. 请更仔细地阅读文档x应该是第一个参数。 Also you need to use a function as input instead of it's return value 另外,您需要使用函数作为输入而不是返回值

def func(x, p1, p2, p3):
    return p1*((p2-x)/p2)^(-p3)

popt, pcov = curve_fit(func, T, Susceptibility) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM