Project

Curve Fitting using MATLAB

OBJECTIVE:

1.Write code to fit a linear and cubic polynomial for the given Cp data.

2.Plot the linear and cubic fit curves along with the raw data points.

CURVE FITTING:

Curve fitting is the process of constructing a curve, or mathematical functions, which possess the closest proximity to the real series of data. By curve fitting, we can mathematically construct the functional relationship between the observed dataset and parameter values, etc. It is highly effective in the mathematical modeling of some natural processes.[1]

in layman's language curve fitting is the process in which a curve can be made which may very close to the original curve and a mathematical formula can be genrated on the basis of that curve so that it can help to forecast future data.

Answer of some of the asked questions are below:

1.How to obtain a perfect curve fit?

A perfect fit can be obtained by interpolating the data because interpolation leads to zero or no error.

2. How to get the best fit?

The best fit curve is that curve when there is a minimum error between the original data and perdicted data, and to get the best fit the degree of polynomial should be changed. here, in this challange the best fit is obtained by increases the degree of polynomial upto 8th degree which shows minimum error.

3.What could be done to improve the cubic fit?

The cubic fit can be improved by splitting the data into small parts and by obtaining the cubic fit for that small parts which leads to decrease in error which in turn improve the fit.

.

Parameters used to measure the characterstics of the curve:

1.SSE(sum of squared errors): This parameter can be obtained by adding and squaring of all the errors between the original data and perdicted data . the lesser the value of SSE is the better the curve is.

2.R-square:

This quantity that measures how successful the fit is in explaining the variation of the data. Put another way, R-square is the square of the correlation between the response values and the predicted response values. It is also called the square of the multiple correlation coefficient and the coefficient of multiple determination.

What that means in layman's terms is that the higher the value of R-square the better the fit, the lower it is the lousier the fit, R-square ranges from a value of 0 to 1

  • 0 for the worst possible fit for the data set
  • 1 for the best possible fit for the data set[1].

so, more the value closer to 1 better the curve is.

3.Adjusted R-square:

Adjusted R-square disregards these infinitesimally small increments to R-square, and only considers the variables which actually contribute to the output of the system in a drastic way.

R-square is formulated as shown below,

where,

n - the number of datapoints

k - the number of independent variables[1]

4.RMSE (Root Mean Squared Error):

This statistic is also known as the fit standard error and the standard error of the regression. It is an estimate of the standard deviation of the random component in the data, and is defined as,

where,

n is the total number of datapoints available.[1]

In this challange these parameter has been calculated(USING CURVE FITTING TOOL) for linear and cubic fit camparisan with original data shown below:

FOR LINEAR FIT:

FOR CUBIC FIT:

CODE USED TO OBTAIN LINEAR AND CUBIC FIT ALONG WITH THE COMPARISION WITH RAW DATA:

clear all
close all
clc

%loading data
cp_data = load('data');

temp = cp_data(:,1);   %temprature in kelvin[K]
cp = cp_data(:,2);    %specific gas constant [kJ/kmol-k]


% linear curve fitting
% two coefficient for linear ax + b
coefficient = polyfit(temp,cp,1);   % to find the cofficient 
%perdicting new cp
new_cp = polyval(coefficient,temp);  % finding new value of cp using calculated
cofficient


%plotting linear curve
figure(1)
plot(temp,new_cp,'linewidth',3)
xlabel('temprature [k]')
ylabel('specific heat [KJ/Kmol-k]')
title('linear fit curve')

%plotting orignal & curve fit data 
figure(2)
hold on
plot(temp,cp,'linewidth',3)
plot(temp,new_cp,'linewidth',3)
xlabel('temprature [k]')
ylabel('specific heat [KJ/Kmol-k]')
legend('original data',' linear curve fit')
title('orignal vs linear curve fit')

%curve fit for cubic polynomial (ax^2 + bx +c)
coefficient1 = polyfit(temp,cp,3);
%perdicting new cp
new_cp1 = polyval(coefficient1,temp);

%plotting cubic curve fit
figure(3)
plot(temp,new_cp1,'linewidth',3)
xlabel('temprature [k]')
ylabel('specific heat [KJ/Kmol-k]')
title('cubic fit curve')

%plotting orignal data & curve fit data using cubic plynomial
figure(4)
hold on
plot(temp,cp,'linewidth',3)
plot(temp,new_cp1,'linewidth',3)
xlabel('temprature [k]')
ylabel('specific heat [KJ/Kmol-k]')
legend('original data','cubic curve fit')
title('original vs cubic curve fit')


EXPLANATION OF THE CODE:

1. First of all, load the original data(which is provided in challange section in the form of pdf) of cp (specific heat ) and temprature into the program by using load command. first coulmn is for cp and 2nd for temprature.

2.Using this data , linear curve fit is created with the help of polyfit and ployval command.

3.Using plot command, plot the linear curve and comare with the original curve.

4. same procedure is needed while creating cubic fit but instead of of 1 in polyfit command 3 degree is used for cube.

NO ERROR WERE FACED WHILE RUNNING THIS PROGRAM.

OUTPUT:

LINEAR FIT PLOT:

LINEAR VS ORIGINAL CURVE:

CUBIC FIT:

ORIGINAL VS CUBIC CURVE FIT:

REFRENCES:

1. https://projects.skill-lync.com/projects/Curve-Fitting-and-criterion-to-choose-best-fit-41860

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.