Curve Fit
Curve Fitting is the process of constructing a curve, or mathematical function, that has the best fit to a series of data points, possibly subject to constraints. Curve fitting can involve either interpolation, where an exact fit to the data is required, or smoothing, in which a \"smooth\" function is constructed that approximately fits the data. A related topic is regression analysis, which focuses more on questions of statistical interference such as how much uncertainty is present in a curve that is fit to data observed with random errors. Fitted curves can be used as an aid for data visualization, to infer values of a function where no data are available, and to summarize the relationships among two or more variables.
clear all
close all
clc
%Preparing the data
cp_data= load(\'data\');
temperature=cp_data(:,1);
cp=cp_data(:,2);
%curve fit
%cp= a*T+b
co_effs = polyfit(temperature,cp,1);
predicted_cp = polyval(co_effs,temperature);
%compare my curve fit with original data
plot(temperature,cp,\'linewidth\',3)
xlabel(\'Temperature[K]\')
ylabel(\'Specific Heat [KJ/Kmole-K]\')
hold on
plot(temperature,predicted_cp,\'linewidth\',3,\'color\',\'r\')
legend(\'Original dataset\',\'Curve fit\')
1) The results are good for a cubic curve fit. However for a linear curve fit, there is quite a bit of deviation at certain points from the original curve due to the nature of variation of specific heat with temperature. Hence the results for a linear curve are bad and not reliable.
2) The curve fit can be made better if the function of dependent variable (here Cp) is expressed as a function of higher order of independent variable.
Generally speaking, linear regression must be tried first. It’s easier to use and easier to interpret. However, if it is simply not possible to get a good fit with linear regression, then it might be time to try nonlinear regression.
The best curve fit is an interpolation. The error will be zero. There are an infinite number of such exact interpolatory models. So the phrase \"perfect curve fit\" is meaningless. If we are willing to have a polynomial, you can get an PERFECT fit with zero error if a Lagrange interpolating polynomial is used. It will go through all the points exactly.