1

I am new to python and I am trying to learn how to plot and fit data. I have an empeirical formula for describing the function y(x) and i want to fit it to an exponential of the form : y = a* x ^ b

I am using numpy.arrays but i am not sure numpy.polyfit is usefull here because i do not want to fit with high order polynomials, neither exponentials of the form : y = a * e ^ (b*x).

Can you please suggest a way to do this?

my function is this one, here written as y (E_n):

E_n = np.linspace(1, 10**6, 10**6)
y= 0.018*(E_n**(-2.7)) * (1/(1+(2.77*cos(45)*E_n/115)) + 0.367/(1+(1.18*cos(45)*E_n/850)))

Thank you

  • 1
    Does this answer your question? [How to do exponential and logarithmic curve fitting in Python? I found only polynomial fitting](https://stackoverflow.com/questions/3433486/how-to-do-exponential-and-logarithmic-curve-fitting-in-python-i-found-only-poly) – Itamar Mushkin May 26 '20 at 11:00

1 Answers1

1

Consider using scipy.optimize.curve_fit. Define a function of the form you desire, pass it to the function. Read the linked documentation well. In many cases, you may need to pass chosen initial values for the parameters. curve_fit takes all of them to be 1 by default, and this might not yield desirable results.

amzon-ex
  • 1,645
  • 1
  • 6
  • 28
  • hey, i tried using curve_fit but the parameters it gives me are 2 dimensional for some reason. i think it has something to do with raising the array to a power. – Konstantina May 27 '20 at 15:19