Project

Curve Fit

quadriatic polynomial [ n= 2]

clear all
close all
clc

% preparing data inputs
cp_data= load(\'data\');
temprature= cp_data(:,1);
cp= cp_data(:,2);

%Curve fit
%cp = a*T^2 + b*T + c
co_effs= polyfit(temprature,cp,2);
predicted_cp= polyval(co_effs,temprature);

%Comparing orginal curve fit with predicted curve fit
plot(temprature,cp,\'linewidth\',3)
hold on
plot(temprature,predicted_cp,\'linewidth\',3,\'color\',\'g\');
xlabel(\'temprature [K]\');
ylabel(\'specific heat [KJ/Kmol-K]\');
legend(\'orginal dataset\',\'curve fit\');

% Finding maximum error between cp and the predicted_cp

error=(cp - predicted_cp)*100/cp;
fprintf(\'Maximum error percentage\');
disp(max(error));

error in quadratic equation =0.00054372 (min.) to 0.00060775 (max.)

-----

Cubic polynomial [n = 3]

clear all
close all
clc

% preparing data inputs
cp_data= load(\'data\');
temprature= cp_data(:,1);
cp= cp_data(:,2);

%Curve fit
%cp = a*T^2 + b*T + c
co_effs= polyfit(temprature,cp,3);
predicted_cp= polyval(co_effs,temprature);

%Comparing orginal curve fit with predicted curve fit
plot(temprature,cp,\'linewidth\',3)
hold on
plot(temprature,predicted_cp,\'linewidth\',3,\'color\',\'g\');
xlabel(\'temprature [K]\');
ylabel(\'specific heat [KJ/Kmol-K]\');
legend(\'orginal dataset\',\'curve fit\');

% Finding maximum error between cp and the predicted_cp

error=(cp - predicted_cp)*100/cp;
fprintf(\'Maximum error percentage\');
disp(max(error));

error in cubic polynomial = 0.00025073 (min.) to 0.00028026 (max.)

------

quartic polynomial [ n=4 ]

clear all
close all
clc

% preparing data inputs
cp_data= load(\'data\');
temprature= cp_data(:,1);
cp= cp_data(:,2);

%Curve fit
%cp = a*T^2 + b*T + c
co_effs= polyfit(temprature,cp,4);
predicted_cp= polyval(co_effs,temprature);

%Comparing orginal curve fit with predicted curve fit
plot(temprature,cp,\'linewidth\',3)
hold on
plot(temprature,predicted_cp,\'linewidth\',3,\'color\',\'g\');
xlabel(\'temprature [K]\');
ylabel(\'specific heat [KJ/Kmol-K]\');
legend(\'orginal dataset\',\'curve fit\');

% Finding maximum error between cp and the predicted_cp

error=(cp - predicted_cp)*100/cp;
fprintf(\'Maximum error percentage\');
disp(max(error));

error in quartic polynomial = 0.00031867 (min.) to 0.00035620 (max.)

------

quintic polynomial [ n= 5]

clear all
close all
clc

% preparing data inputs
cp_data= load(\'data\');
temprature= cp_data(:,1);
cp= cp_data(:,2);

%Curve fit
%cp = a*T^2 + b*T + c
co_effs= polyfit(temprature,cp,5);
predicted_cp= polyval(co_effs,temprature);

%Comparing orginal curve fit with predicted curve fit
plot(temprature,cp,\'linewidth\',3)
hold on
plot(temprature,predicted_cp,\'linewidth\',3,\'color\',\'g\');
xlabel(\'temprature [K]\');
ylabel(\'specific heat [KJ/Kmol-K]\');
legend(\'orginal dataset\',\'curve fit\');

% Finding maximum error between cp and the predicted_cp

error=(cp - predicted_cp)*100/cp;
fprintf(\'Maximum error percentage\');
disp(max(error));

error in quintic polynomial = 0.00034326(min.) to 0.00038368 (max.)

RESULT-

In order to get best curve fit we need to increase the degree of polynomial.

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.