Python Forum

Full Version: curve_fit
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hallo all

I am processing data to use curve_fit and the the code program like this
import csv
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit

def langmuir(x,a,b,c,d):
return np.exp(a*np.tanh((x+b)/c))+d;

popt, pcov = curve_fit(langmuir, Voltage, Current)

that code if I running that code is not error, I try to optimization with given some values, the code like this
popt, pcov = curve_fit(langmuir, Voltage, Current,bonds=(1,5,-5,0)),
if i running, the code will be error and the message error are
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/scipy/optimize/minpack.py", line 736, in curve_fit
res = leastsq(func, p0, Dfun=jac, full_output=1, **kwargs)
have you any idea for fix that code ?

thank you very much
Try
popt, pcov = curve_fit(langmuir, Voltage, Current,bonds=([1,5],[-5,0]))
Error:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/scipy/optimize/minpack.py", line 736, in curve_fit
I dont know how useful that error message. Can you provide with the fill stack trace?

And also I noticed shouldn't bonds must be spelled bounds?

popt, pcov = curve_fit(langmuir, Voltage, Current, bounds=([1,5],[-5,0]))