CurveFit in Matlab
ans.1=> With Linear Polynomial the Obtained fit was a straight line which was not matching the original curve. But with cubic Polynomial the curvefit was nearly accurate upto terimal of the curve where it deviated slightly.
ans.2=>Use of Approprite Mathematical Fuction with Different Curves e.g high order polynomials, interpolation, exponentials functions etc. would help in making a curvefit accurate.
close all
clear all
clc
%Praparing Data
info = load(\'data\');
temperature = info(:,1);
cp = info(:,2);
%curve fit
%cp = a*t + b
co_effs = polyfit(temperature,cp,1);
predicted_cp = polyval(co_effs,temperature);
%cp = a*T^3 + b*T^2 + c*T + d
co_eff = polyfit(temperature,cp,3);
pred_cp = polyval(co_eff,temperature);
figure(1)
plot(temperature,cp,\'linewidth\',2)
hold on
plot(temperature,predicted_cp,\'linewidth\',2)
xlabel(\'temperature [K]\')
ylabel(\'Specific Heat [KJ/K]\')
legend(\'Original Data\',\'Predicted Curvefit\')
figure(2)
plot(temperature,cp,\'linewidth\',2)
hold on
plot(temperature,pred_cp,\'linewidth\',2)
xlabel(\'temperature [K]\')
ylabel(\'Specific Heat [KJ/K]\')
legend(\'Original Data\',\'Predicted Curvefit\')
%Error
error = (cp-pred_cp).*100./cp;
fprintf(\'Maximum Error in the CurveFit with cubic polynomial\')
disp(max(error))
fprintf(\'Average Error in the CurveFit with cubic polynomial\')
disp(mean(error))