Categories
Python Answers

How to do exponential and logarithmic curve fitting in Python?

Spread the love

Sometimes, we want to do exponential and logarithmic curve fitting in Python.

In this article, we’ll look at how to do exponential and logarithmic curve fitting in Python.

How to do exponential and logarithmic curve fitting in Python?

To do exponential and logarithmic curve fitting in Python, we fit y against log x.

For instance, we write

x = numpy.array([1, 7, 20, 50, 79])
y = numpy.array([10, 19, 30, 35, 51])
numpy.polyfit(numpy.log(x), y, 1)

to call numpy.array to create NumPy arrays of x and y axis values.

Then we call numpy.polyfit with numpy.log(x), which is an array with the log of each value in x, y, and 1 to do logarithmic curve fitting.

Conclusion

To do exponential and logarithmic curve fitting in Python, we fit y against log x.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *