Project

CURVE FITTING

CURVE FITTING USING MATLAB

INTRODUCTION TO 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.

Statical Inference is defined as, such as how much uncertainty is present in a curve that is fit to data observed with random errors. Fitted curves can be used as an aid for data visualization to infer values of a function where no data are available and to summarize the relationships among two or more variables.

Extrapolation refers to the use of a fitted curve beyond the range of the observed data and is subject to a degree of uncertainity since it may reflect the method used to construct the curve as much as it reflects the observed data.

Regression analysis is a powerful statistical method that allows you to examine the relationship between two or more variables of interest.

DEGREE OF POLYNOMIAL:

The degree of polynomials in one variable is the highest power of the variable in the algebraic expression.

example : x2+2x+4 (the degree of polynomial is 2)

LINEAR CURVE FIT:

In the context of curve fitting, a linear curve is a curve that has a linear dependence on the curve parameters. A linear combination is therefore defined by the function basis and the coefficients of the basis functions in the combination.

CUBIC CURVEFIT:

Calculation instructions for many commercial assay kits recommend the use of a cubic regression curve-fit (also known as 3rd order polynomial regression). This turning point means that the curve cannot be used to interpolate concentration values for measurements within the range.

GOODNESS OF FIT:

The goodness of fit of a statistical model describes how well it fits a set of observations. Measures of goodness of fit typically summarize the discrepancy between observed values and the values expected under the model in question.

PARAMETRES USED TO INCREASE THE MEASURE OF ERROR

  • SSR =Sum of Square of Regression.
  • SSE =Sum of Square of Error.
  • SST =Sum of Squared Total.
  • Adjusted R^2=R-Squared is a statistical measure of fit that indicates how much variation of a dependent variable is explained by the independent variable(s) in a regression model.
  • RMSE =Root Mean Square Error.

FORMULAS USED:

PROBLEMS GIVEN:

case1:Write code 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. Title and axes labels are a must, legends could be shown if necessary.

case2:Explain the parameters used to measure the fitness characteristics for the curves fit.

SOLUTION FOR case1:

Code and plot to fit a linear polynomial and cubic polynomial for the Cp data.

clear all
close all
clc


%preparing the data
cp_data = load('data');
temperature = cp_data(:,1);
cp = cp_data(:,2);
  
%fitting for linear curvefit
co_effs = polyfit(temperature,cp,1)
predicted_cp = polyval(co_effs,temperature)
SSE=0;
SSR=0;
sum=0;

%input for cubic curvefit
co_eff1 = polyfit(temperature,cp,3)
predicted1cp = polyval(co_eff1,temperature)
SSE1=0;
SSR1=0;
sum1=0;

%to fond SSR SSE R^2 for linear fit
for i = 1:length(cp);
    SSE=SSE+(cp(i)-predicted_cp(i))^2;
    sum=sum+(cp(i));
    
end
mean=sum/length(cp);

for i =1:length(cp);
    SSR=SSR+(predicted_cp(i)- mean)^2;
end

SST=SSE+SSR
R_square =(SSR/SST)
RMSE =(SSE/length(cp))^0.5


%to fond SSR SSE R^2 for cubic fit
for i = 1:length(cp);
    SSE1=SSE1+(cp(i)-predicted1cp(i))^2;
    sum1=sum1+(cp(i));
    
end
mean1=sum1/length(cp);

for i =1:length(cp);
    SSR1=SSR1+(predicted1cp(i)- mean1)^2;
end

SST1=SSE1+SSR1;
R1_square = SSR1/SST1;
RMSE1 =(SSE1/length(cp))^0.5;


%compare predicted_cp and originaldataset
plot(temperature,cp,'linewidth',3,'color','r');
hold on
plot(temperature,predicted_cp,'linewidth',3,'color','g');
plot(temperature,predicted1cp,'linewidth',3,'color','b');
xlabel('temperature [K]')
ylabel('cp [KJ/KMOL-K]')
legend('originaldataset','linearfit','cubicfit','location','southeast')
title('linearfit and cubicfit with originaldataset')

WORKSPACE VALUES:

WORKSPACE VALUES FOR LINEARFIT WORKSPACE VALUES FOR CUBICFIT

PLOT FOR LINEAR AND CUBIC POLYNOMIAL:

CODES FOR case2:

clear all
close all
clc

results = load('data');
temp = results(:,1);
cp = results(:,2);

a = 1;
b = 400;
for i = 1:8;
    co_eff = polyfit(temp(a:b),cp(a:b),2)
    pre_cp(a:b) = polyval(co_eff,temp(a:b))  
    a = b+1;
    b = b+400;
    
end
%to fond SSR SSE R^2 
SSE=0;
SSR=0;
sum=0;
for i = 1:length(cp);
    SSE=SSE+(cp(i)-pre_cp(i))^2;
    sum=sum+(cp(i));
    
end
mean=sum/length(cp);

for i =1:length(cp);
    SSR=SSR+(pre_cp(i)- mean)^2;
end

SST=SSE+SSR
R_square = SSR/SST
RMSE =(SSE/length(cp))^2

plot(temp,cp,'color','r');
hold on
plot(temp,pre_cp,'color','g');
title('curvefit');

WORKSPACE VALUES FOR CURVEFIT:

PLOT FOR CURVEFIT:

CONCLUSION:

By taking the correct quatities shown below determined the goodness of curve fit.

1.Sum of Square of Regression.

2.Sum of Square of Error.

3.Sum of Squared Total.

4.Adjusted R^2

5.Root Mean Square Error.

By taking the above parametres the mesure of error reduction is incresed.

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.