Curve fitting
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.