Project

Curve fitting Temp vs Specific heat

%curve fitting by Chinmay Gabel
clear all
clc
close all

%getting the inputs
cp_data = load(\'data\');
temp = cp_data(:,1);
cp = cp_data(:,2);

%curve fitting 
coeff_linear = polyfit(temp,cp,1);
predicted_cp_linear = polyval(coeff_linear,temp);

coeff_cubic = polyfit(temp,cp,3);
predicted_cp_cubic = polyval(coeff_cubic,temp);

plot(temp,cp)
hold on
plot(temp,predicted_cp_linear,\'color\',\'r\')
plot(temp,predicted_cp_cubic,\'color\',\'g\')
xlabel(\'Temperature (in K)\')
ylabel(\'Specific Heat (in KJ/K-mol-k)\')
legend(\'Original data\',\'Curve fit (linear)\',\'Curve fit (cubic)\')

%calculating mean percentage error of linear curve fitting
difference_linear = abs(cp - predicted_cp_linear);
percentageDifference_linear = difference_linear ./ cp; 
meanPctDiff_linear = mean(percentageDifference_linear)

%calculating mean percentage error of cubic curve fitting
difference_cubic = abs(cp - predicted_cp_cubic);
percentageDifference_cubic = difference_cubic ./ cp; 
meanPctDiff_cubic = mean(percentageDifference_cubic)

From the error calculation, it can be seen that the cubic approximation is way far better than the linear approximation

In order to make the curve fit more perfect the order of polynomial should be increased. More the order higher will be the accuracy.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.