Project

curve fitting

CURVE FITTING FOR THE LINEAR AND CUBIC POLYNOMIAL FUNCTION USING THE MATLAB.

Introduction:

curve fit: curve fitting is the process of constructing the constructing a curve using the mathematical functions ,which posses the closest proximity to the real series of the data,by curve fitting ,we can mathematically construct the fuctional relationship between the observed data set and the parameter values etc,highly effective in mathematical modelling of same natural process.

here we calucate the values by using the methods like :

R-square method,

Adjusted R-square method ,

SSE(Sums of Squared Errors),

Root Mean Square Method .

in this matlab program we use the polyfit and polyval as the commands

polyfit & polyval: Polyfit is a Matlab function that computes a least squares polynomial for a given set of data. Polyfit generates the coefficients of the polynomial, which can be used to model a curve to fit the data. Polyval evaluates a polynomial for a given set of x values.

here we do the computational for the linear and the cubical polynomials and aompare the better degree for curve fitting.

the code of the matalab is :

close all 
clear all
clc

%load data set

cp_data=load('data');
temperature=cp_data(:,1);
cp=cp_data(:,2);

%For curve fit
%Equation cp=a*T^2+b*T+c

%linear curve fit calculation 

co_eff=polyfit(temperature,cp,1)
predicted_cp=polyval(co_eff,temperature)



%comparing the predicted and real value of cp

figure(1)
plot(temperature,cp,'linewidth',3)

hold on
plot(temperature,predicted_cp,'linewidth',4,'color','r')
xlabel('TEMPERATURE[k]')
ylabel('specific heat[kj/kmol-k')
legend('original dataset','curve fit')
title('LINEAR')



%Calculation of sum of squared error

error=predicted_cp(:,1)-cp(:,1);
SSE=sum(error.^2);

%calculation of sum of squares of regression

SSR=sum((cp(:,1)-mean(cp(:,1))).^2);


%calculation of R_square

SST=SSR+SSE;
R1_square=SSR/SST

%determination of nature of fit

if R1_square>0.95
    display('fit is good')
    
else
    
    display('fit is not good')
    
end
 
 
 %calculation for the cubic function
co_effs=polyfit(temperature,cp,3)
predicted_cp=polyval(co_effs,temperature)



%comparing the predicted and real value of cp

figure(2)
plot(temperature,cp,'linewidth',3)

hold on
plot(temperature,predicted_cp,'linewidth',4,'color','r')
xlabel('TEMPERATURE[k]')
ylabel('specific heat[kj/kmol-k')
legend('original dataset','curve fit')
title('LINEAR')



%Calculation of sum of squared error

error=predicted_cp(:,1)-cp(:,1);
SSE=sum(error.^2);

%calculation of sum of squares of regression

SSR=sum((cp(:,1)-mean(cp(:,1))).^2);


%calculation of R_square

SST=SSR+SSE;
R1_square=SSR/SST

%determination of nature of fit

if R1_square>0.95
    display('fit is good')
    
else
    
    display('fit is not good')
    
end

Bestfit: the best fit is defined as the curve fit that we are constructing using the mathematical equation is approximately same as the the data set curve.simply to say the curve formed by the actual data must be same as the curve that we constructed by the mathematically.

Good fit: good fit of the curve is defined by the value 0.95

if the value calculated by above mentions methods is less than 0.95 then it is a bad fit ,else it is a good fit.

calculation:

The value of R-square can be calculated using the following formula:

Where

SSR = sum of squares of the regression, which is basically the square of the difference between the value of the fitting function at a given point and the arithmetic mean of the data set.

Using these four quantities Matlab effectively deduces the goodness of fit, typically is R-square is greater than 0.95 the fit is assumed to be good.

The curve fit can be made more perfect by increasing the order of the polynomial used.

Results:

From the figure we can say that the curve fit for the actual data is not best fit and not a good fit.

from the above figure the curve fit curve is adjusting to the actual data set .

conclusion:

from the above results we can say that by increasing the degree of polynommial ,the curve fitting will be good.the results will be more accurate.

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.