Project

code to fit a linear and cubic polynomial for the Cp data

%FOR LINEAR  POLYNOMIAL


clear all
close all
clc
%preparing the data
cp_data=load(\'datahw\');
temperature=cp_data(:,1);
cp=cp_data(:,2); 
 
% Curve fit
% cp= aT^2 + b*T + c
co_effs= polyfit(temperature,cp,1);
predicted_cp = polyval(co_effs , temperature);
 
%compare my curve fit with the original one
hold on
 plot(temperature,cp,\'linewidth\',2);
 plot(temperature,predicted_cp,\'linewidth\',3,\'color\',\'r\');
xlabel(\'Temperature [K]\');
 ylabel(\'Specific Heat [KJ/Kmol-K]\');
 legend(\'Original data\',\'Curve fit\')


%FOR CUBIC POLYNOMIAL


clear all
close all
clc
%preparing the data
cp_data=load(\'datahw\');
temperature=cp_data(:,1);
cp=cp_data(:,2); 
 
% Curve fit
% cp= aT^2 + b*T + c
co_effs= polyfit(temperature,cp,3);
predicted_cp = polyval(co_effs , temperature);
 
%compare my curve fit with the original one
hold on
 plot(temperature,cp,\'linewidth\',2);
 plot(temperature,predicted_cp,\'linewidth\',3,\'color\',\'r\');
xlabel(\'Temperature [K]\');
 ylabel(\'Specific Heat [KJ/Kmol-K]\');
 legend(\'Original data\',\'Curve fit\')

%THE CURVE FOR LINEAR AND CUBIC POLYNOMIAL RESPECTIVELY

%EXPLANATION

From the above curves we can see that the linear curve is far away from the original data given and the cubic curve is almost as the given curve means the errors are less in the cubic curve .

Now if we increase the polynomial degree we can see that the predicted curve is going to be the same as the given curve . Means the errors are going to be less for a higher degree polynomial.

In order to make the curve fit perfect 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.