您好,您的mpfit.py这个文件在哪下的
请问Python中非线性拟合mpfit怎么使用?
由于需要利用L-M算法进行光谱拟合,所以下载了mpfit.py文件使用,但是不是很清楚用法;我尝试拟合最简单的线性函数,但是结果完全不正确;初始参数未经任何改变就被输出;代码如下,不太清楚错误在哪里;希望各位帮忙。
import mpfit as mt
import numpy as np
import random
import types
x=np.arange(0,10,0.1)
y=[]
for i in range(np.size(x)):
y.append(5*x[i]+3+random.randrange(0,1))
def myfunct(p, fjac=None,x=None, y=None, err=None):
model=p[0]*x+p[1]
status=0
return([status,(y-model)/(err)])
p0=[10,9]
fa = {'x':x, 'y':y,'err':0.1}
m=mt.mpfit(myfunct,p0,functkw=fa)
print ('status = ', m.status)
if (m.status <= 0):
print ('error message = ', m.errmsg)
print ('parameters = ', m.params)
输出:
status = 4
parameters = [10. 9.]
- 点赞
- 写回答
- 关注问题
- 收藏
- 复制链接分享
- 邀请回答
2条回答
为你推荐
- 在Python3.9.2里如何安装pygame???
- 开发语言
- 有问必答
- python
- 3个回答
- 如何对指数积分进行非线性拟合
- python
- 1个回答
- 在软件中使用Python,软件需要开源吗?
- python
- 2个回答
- 如何matlab或者python实现多元函数的非线性拟合。
- python
- r语言
- 3个回答
- 请问现在Python连接,操作数据库用什么?
- python
- mysql
- 1个回答
- 为什么python使用线程池会丢失部分数据?
- python
- 1个回答
- Python中的print语句输出?
- python
- 5个回答
- Python 如何去掉列表中的引号?
- python
- 2个回答
- python3.8 字符串输入了中文字符 为什么没有报错
- python
- 2个回答
- 为什么python中print函数无法正常使用end,sep?
- python
- 2个回答
- python更新pip失败,困扰了我好久
- python
- 8个回答
- python 二维数组操作问题
- python
- 1个回答
- 请问python中如何将字符转化成16进制数字?
- python
- 2个回答
- python中的remove函数报错FileNotFoundError?
- 机器学习
- 神经网络
- python
- tensorflow
- 2个回答
- Python中的PHP str_replace?
- php
- python
- 2个回答
- 请问python如何判断字符串中第n项的字符?
- python
- 2个回答
- 为什么python中while不能使用全局变量呢??
- 开发语言
- python
- 1个回答
- python字典中键值使用变量?
- python
- 4个回答
- python中的字典赋值问题???
- python
- 3个回答
- Python 画一朵彩色玫瑰花
- python
- 1个回答