Curve fitting
1. a)Popt: Popt gives the optimal values of the parameters. For ex: if the equation is ax+b, the curve_fit will return the optimal values of a & b in popt.
b)Pcov: Pcov gives the estimated covariance of popt. It is used to calculate the standard deviation errors on the parameters using np.sqrt(np.diag(pcov)).
2. np.array(temperature): It converts the lists temperature to the numpy array so the various mathematical operations can be performed on the data.
3. The * in *popt unpacks the popt array so the optimized values can become the arguments of the function.
4. The code to fit the linear and cubic polynomial for Cp data. I have made this code so that it can fit half of the values as linear and the other half as cubic equation.
Objective: To perform curve fitting on the given Cp vs Temperature data file.
Concept: The best way to perform curve fitting will be to first plot the data file provided in the assignment and then find the best suited equation to represent the curves.
Methodology:
1. The first step would be to define a function to read the file 'data' and plot and show the graph.
The graph will plotted is shown below:
2. Now from the graph it shown the curve is showing charaterstics of cubic equation in some the first part and the linear equation in some of the later part. Let us assume the half of the values are showing cubic characterstics and half are showing linear characterstics. Therefore the second step will be to define the functions for the same i.e.
a) The function to count the no. of lines
b) The function defining linear relations
c) The function defining cubic relation.
3. The third step would be to modify the read function so that it returns the vaules of both temperature and cp into two parts so that they can be used separately.
4. The last step would be to use the curve_fir function imported from scipy.optimize, to find the optimum values of parameters for function1 and function2. and then to calculate fit_cp1 and fit_cp2 so that it can be used for fitting of the curve.Append cp1 and cp2, and fit_cp1 and fit_cp2 into a single array i.e. cp and fit_cp.
Now the graph shown will be:
5. According to me, the results i have gotton are quite good as they are defining the curve almost perfectly.
And the Output: