0

I was trying to solve a cubic equation and to fit with my experimental data set. But there is some problem in my code regarding curve_fit. Though both function f and del_y defined perfectly (checked using values of parameters ), curve_fit is not working and showing me the error :

ValueError: setting an array element with a sequence.

Can somebody help me out of this ?

import numpy as np
from scipy.optimize import curve_fit

def f(G0,H0,k1,k2):
    a=(k1+2*k1*k2*H0-k1*k2*G0)/(k1*k2)
    b=(1+k1*H0-k1*G0)/(k1*k2)
    c=-G0/(k1*k2)
    cf=[1,a,b,c]
    k=np.roots(cf)
    return abs(k[2])

def del_y(G0,H0,A,k1,k2,n):
    return A*(0.04*k1*f(G0,H0,k1,k2)**n)
popt, pcov = curve_fit(del_y,x_data,y_data)
SuperKogito
  • 2,998
  • 3
  • 16
  • 37
user74361
  • 9
  • 3
  • 1
    Can you please provide the mathematical equation(s) you are trying to fit your data to. The roles of your variables are unclear. I think you have a dimentionality issue in your `cf`. – SuperKogito Sep 12 '19 at 09:19
  • y=A*(0.04*k1*f(x,H0,k1,k2)**n) this is my fitting equation. I have a data set (x_data,y_data). I want to fit it with the data. – user74361 Sep 12 '19 at 10:53
  • provide a minimal example! the dimensions of your variables are unclear. – SuperKogito Sep 12 '19 at 11:50

0 Answers0