curve fitting
close all
clear all
clc
cp_load=load(\'data\')
temperature=cp_load(:,1);
cp=cp_load(:,2);
%linear: cp=a*T+b
%cubic polynomial: cp=a*T^3+b*T^2+c*T+d
coeffs1= polyfit(temperature,cp,1);
predicted_cp1=polyval(coeffs1,temperature);
coeffs= polyfit(temperature,cp,3);
predicted_cp=polyval(coeffs,temperature);
%plotting
plot(temperature,cp,\'linewidth\',2,\'color\',\'g\')
hold on
plot(temperature,predicted_cp1,\'linewidth\',2,\'color\',\'r\')
hold on
plot(temperature,predicted_cp,\'linewidth\',2,\'color\',\'b\')
xlabel(\'TEMPERATURE[K]\')
ylabel(\'SPECIFIC HEAT[K/ Kmol-K]\')
legend(\'original dataset\',\'linear\',\'cubic polynomial\')
***************************************************************************************
%For perfect curve fitting
close all
clear all
clc
cp_load=load(\'data\')
temperature=cp_load(:,1);
cp=cp_load(:,2);
%linear: cp=a*T+b
%cubic polynomial: cp=a*T^3+b*T^2+c*T+d
coeffs1= polyfit(temperature,cp,1);
predicted_cp1=polyval(coeffs1,temperature);
coeffs= polyfit(temperature,cp,3);
predicted_cp=polyval(coeffs,temperature);
coeffs6= polyfit(temperature,cp,8);
predicted_cp6=polyval(coeffs6,temperature);
%plotting
plot(temperature,cp,\'linewidth\',2,\'color\',\'g\')
hold on
plot(temperature,predicted_cp1,\'linewidth\',2,\'color\',\'r\')
hold on
plot(temperature,predicted_cp,\'linewidth\',2,\'color\',\'b\')
hold on
plot(temperature,predicted_cp6,\'linewidth\',2,\'color\',\'y\')
xlabel(\'TEMPERATURE[K]\')
ylabel(\'SPECIFIC HEAT[K/ Kmol-K]\')
legend(\'original dataset\',\'linear\',\'cubic polynomial\',\'8th degree\')
1.code to fit the dataset with the cubical polynomial is attached and the out put obtained in form of plot is also attached. As see in the plot the cubical polynomial doesnt perfectly fit with the dataset there is some error.
3.In order to fit the curve perfectly with the dataset the order of the polynomial is increased.
2.As seen in fig.2 for the given cp n temperature data the 8th order polynomial perfectly fits to the original dataset curve. further its also compared with the linear curve.