Performing Curve Fitting in Splitwise method using Matlab.
Aim : Code to perform curve fitting in linear polynomial fit splitwise method using matlab.
Objective : To code curve fitting for specific heat and temperature datas,in linear polynomial fit .And to obtain the plot for predicting the data set.
clear all
close all
clc
% inputs datas of specific heat and Temperature
cp_data = load('data');
temperature = cp_data(:,1);
cp = cp_data(:,2);
% Inputs of temperatures using splitwise method
t1 = temperature(1:800);
t2 = temperature(801:1600);
t3 = temperature(1601:2400);
t4 = temperature(2401:3200);
% Inputs of specific heat using splitwise method
cp1 = cp(1:800);
cp2 = cp(801:1600);
cp3 = cp(1601:2400);
cp4 = cp(2401:3200);
% storing the valves of temperature and specific heat in polynomial
co_eff1 = polyfit(t1,cp1,2);
co_eff2 = polyfit(t2,cp2,2);
co_eff3 = polyfit(t3,cp3,2);
co_eff4 = polyfit(t4,cp4,2);
Predicted_cp1 = polyval(co_eff1,t1);
Predicted_cp2 = polyval(co_eff2,t2);
Predicted_cp3 = polyval(co_eff3,t3);
Predicted_cp4 = polyval(co_eff4,t4);
% plotting the graph
plot(temperature,cp,'linewidth',3)
hold on
plot(t1,Predicted_cp1,'linewidth',3,'color','r')
plot(t2,Predicted_cp2,'linewidth',3,'color','b')
plot(t3,Predicted_cp3,'linewidth',3,'color','g')
plot(t4,Predicted_cp4,'linewidth',3,'color','r')
xlabel('temperature [k]')
ylabel('specific heat[KJ/KMol-K]')
legend('original dataset','curvefit1','curvefit2','curvefit3','curvefit4')
Conclusion : The obtained curve fit are shown below
