Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
curve_fit
#1
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
Reply
#2
Use code tags please see: https://python-forum.io/misc.php?action=help
Reply
#3
Try
popt, pcov = curve_fit(langmuir, Voltage, Current,bonds=([1,5],[-5,0]))
When my code doesn't work I don't know why **think** and when my code works I don't know why **think**
Reply
#4
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]))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using scipy.optimize: curve_fit ju21878436312 0 954 Sep-24-2022, 01:15 PM
Last Post: ju21878436312
  How to get coefficient of determination R2 after scipy.curve_fit? AlekseyPython 0 1,870 Feb-12-2021, 09:03 AM
Last Post: AlekseyPython
  scipy curve_fit for multiple independent variables Jay_Nerella 1 7,180 May-08-2019, 02:08 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020