Curve Fit
clear all
close all
clc
%load and assign input
predicted= load(\'data1\');
temp= predicted(:,1);
cp= predicted(:,2);
coeff= polyfit(temp,cp,1);
coeffs= polyfit(temp,cp,3);
cp_pred= polyval(coeffs, temp);
cp_pred1= polyval(coeff, temp);
plot(temp,cp,\'linewidth\',3,\'color\',\'r\');
hold on
plot(temp,cp_pred,\'linewidth\',3,\'color\',\'b\');
legend(\'from data\',\'predicted\');
xlabel(\"Temperature\");
ylabel(\"c_p\");
figure;
plot(temp,cp,\'linewidth\',3,\'color\',\'r\');
hold on
plot(temp,cp_pred1,\'linewidth\',3,\'color\',\'b\');
legend(\'from data\',\'predicted\');
xlabel(\"Temperature\");
ylabel(\"c_p\")
Result:
1. using 3rd order polynomial gives more accurate curve fit than 1st order.
2. Error should be minimised between actual and predicted values.