curve fitting for temperature vs specific heat data
Here in this assignment I make code for curve fitting for data of Temperature vs Specific Heat.
Hear I make to curve fitting one with linear polynomial relation and another with cubic polynomial relation. In this we are first of all find cofficient of equation and than by using them we find new value of cp and make another plot between temperature vs predicted_cp.
As you show here cubic polynomial plot is more relevant than linear polynomial. show I can say that the given data of temperature and specific heat have cubic mathematical relation.
We are using this curve fitting to find mathematical relation between two different data.
Result with linear polynomial plot is not as much good because there is huge difference between two the plot. But result with cubic polynomial plot its very good I can say because the different between two plot is very less.
If we want that our curve fit became more perfect for that we have to increse the value of polynomial and curve became more perfact and different between two graph will less.
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^3 + b*t^2 + c*t + d
ct = 1;
for i=1:1
co_effs = polyfit(temperature,cp,3);
predict_cp = polyval(co_effs, temperature);
%compare my curve fit with the original data
plot(temperature, cp, \'linewidth\', 3, \'color\', \'r\')
hold on
plot(temperature, predict_cp, \'linewidth\', 3, \'color\', \'g\')
xlabel(\'temperature [K]\')
ylabel(\'specific heat [Kj/Kmol-K]\')
legend(\'original dataset\', \'curve fit\')
ct = ct+1;
end
figure(ct)
% curve if polynomial is linear
for j=2
co_effs1 = polyfit(temperature,cp,1);
predict_cp1 = polyval(co_effs1, temperature);
plot(temperature, cp, \'linewidth\', 3, \'color\', \'r\')
hold on
plot(temperature, predict_cp1, \'linewidth\', 3, \'color\', \'g\')
xlabel(\'temperature [K]\')
ylabel(\'specific heat [Kj/Kmol-K]\')
legend(\'original dataset\', \'curve fit\')
end