Curve Fitting Solution
Curve Fitting Solution
This document contains the Python code and explanation for solving problems related to curve
fitting using the Least Squares Approximation method. The curve fitting is performed with a
polynomial of degree 2 for given data points, and an exponential function is used for fitting the data
of Problem 2.
x = [5, 6, 7, 8, 9]
The Python code for fitting the polynomial curve using least squares approximation of degree 2 is as
follows:
import numpy as np
return coefficients
plt.xlabel("x")
plt.ylabel("y")
plt.title(title)
plt.legend()
plt.show()
# Problem 1
x1 = np.array([5, 6, 7, 8, 9])
x = [1, 2, 3, 4, 5]
The Python code for fitting the data to the exponential curve y = ae^(bx) is as follows:
import numpy as np
x2 = np.array([1, 2, 3, 4, 5])
log_y2 = np.log(y2)
a = np.exp(coeffs2[1])
b = coeffs2[0]