Project

TO PLOT A CURVE FITTING OF A LINEAR POLYNOMIAL AND CUBIC POLYNOMIAL FOR THE GIVEN Cp DATA

AIM OF THE PROJECT:

to fit a linear and cubic polynomial for the Cp data. And plot the linear and cubic fit curves along with the raw data points.

WHAT IS CURVE FITTING?

Curve fitting is the process of constructing a curve, or mathematical function, that has the best fit to a series of data points, possibly subject to constraints. Curve fitting can involve either interpolation, where an exact fit to the data is required, or smoothing, in which a "smooth" function is constructed that approximately fits the data.

WHAT IS LINEAR POLYNOMIAL?

A linear polynomial is any polynomial defined by an equation of the form p(x) = ax + b where a and b are real numbers and a 6= 0. For example, p(x)=3x 7 and
q(x) = 13
4 x+ 5
3 are linear polynomials. A linear polynomial is the same thing as a degree 1 polynomial.

WHAT IS CUBIC POLYNOMIAL?

A polynomial whose degree is 3 is termed as a cubic polynomial. Hence any cubic polynomial in one variable x is of the form ax3 + bx2 + cx + d, where a, b, c and d are constants and a ≠ 0.

USE OF CURVE FITTING:

Curve Fitting is used to find the "best fit" line or curve for a series of data points. Most of the time, the curve fit will produce an equation that can be used to find points anywhere along the curve.

PROCEDURE FOR LINEAR AND CUBIC POLYNOMIAL CURVE FIT FOR THE Cp DATA :

clear all
close all
clc
%loading the data
cp_data=load('data');
temperature=cp_data(:,1);
cp=cp_data(:,2); 
 
% Curve fit
% cp= aT^2 + b*T + c
coeff_s= polyfit(temperature,cp,1);
predicted_cp = polyval(coeff_s , temperature);
 
%compare this 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('data');
temperature=cp_data(:,1);
cp=cp_data(:,2); 
 
% Curve fit
% cp= aT^2 + b*T + c
coeff_s= polyfit(temperature,cp,3);
predicted_cp = polyval(coeff_s , temperature);
 
%compare 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')

STEP BY STEP EXPLANATION OF THE ABOVE CODE:

  • Loading the given data in the MATLAB program by using 'load' Command.
  • Store the 1st column of given data as temperature and 2nd column of given data as Specific Heat (sp)
  • Use Degree of Polynomial as 1 to fit a linear fit curve of Specific heat (sp) given data.
  • Use 'Polyfit' command to get a actual linear fit curve of Specific heat.
  • Use 'Polyval' command to get a predicted linear fit curve of Specific heat.
  • Use 'plot' command to plot the Actual and Predicted linear fit curve of Specific heat.
  • Use Degree of Polunomial as 3 to fit a cubic fit curve of Specific heat (sp) given data.
  • For finding R-square value , first we want to find the sse,ssr,sst values.
    R^2 = SSR / SST
    SSR = (f(x(i)) - Mean)^2
    SSE = (y(i)-f(x(i)))^2
    SST = SSR+SSE
  • After using all above formulas to finding R-square, run the program to get the value of R-squar

OUTPUT FOR THE ABOVE PROGRAM:

CONCLUSION:

from the above result we can say, In order to make the curve fit perfect, we have to increase the order of the polynomial so that the error will be minimum. then the curve will be perfect.

ERROR DURING THE EXECUTION OF CODE:

Syntax errors and some minor mistakes are obtained during the execution of code, it can be resolved by checking syntaxes again and again
Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the
polynomial, or try centering and scaling as described in HELP POLYFIT.
> In polyfit (line 72)
In curve_fit_copy (line 36)

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.