Project

CURVE FITTING OF THE SPECIFIC HEAT DATA

AIM: TO WRITE A PROGRAM FOR CURVE FITTING OF THE SPECIFIC HEAT DATA USING MATLAB/OCTAVE.

OBJECTIVE:

· To write a program to fit a linear and cubic polynomial for the Cp data.

· To plot the linear and cubic fit curves.

· To explain the parameters used to measure the fitness characteristics for both the curves.

· To find the methods of improvement of the cubic fit.

OVERVIEW AND GOVERNING EQUATIONS:

Curve fitting is one of the most powerful and most widely used analysis tool in origin. curve fitting examines the relationship between one or more independent variables and a response variable, with the goal of defining a “best fit” model of the relationship. unfortunately, the real world isn’t always nice and neat like this. Sometimes our data have curved relationship between variables but the charge in the dependent variable associated with one-unit shift in the independent variables varies based on the location in the observation space.

Origin provides tools for linear, polynomial, and nonlinear curve fitting along with validation and goodness of fit tests.

Least square method-

polynomial-

Equation of the form:

y(x)=anxn+an-1xn-1+……………+a1x+a0

(here, n is the degree of the polynomial)

step-1: square the error.

ek = yk – f(xk)

step-2: sum the square errors for all data points.

E=ΣE = \Sigma E=Σk=1n[ek]2

step-3: minimize the results from step-2.

To get best curve fit,minimize the errors >>

Upon finding a curve which satisfies the data points there are 4 quantities which help us measure the goodness of fit criteria or how well the equation is a representing the datapoints-

1. The sum of squares due to error (SSE)

2. R-square

3. Adjusted R-square

4. Root mean squared error (RMSE)

1. The sum of squares due to error(SSE):

here, TSS=Total sum of squares=Σ\SigmaΣ(yi-ymean)2

RSS=Residual sum of squares=Σ\SigmaΣ(yi-yfitted)2

ESS=Explained sum of squares=Σ(yfitted-ymean)2

2. R-square:

R-square=RSS/TSS or 1-(ESS/TSS)

3. Adjusted R-square:

Adjusted R-square is a normalizing variation of R-square which neglects the variation of R-square due to insignificant independent variables.are is a normalizing variation of R-square which neglects the variation of R-square due to insignificant independent variables.

4. Root mean squared error(RMSE):

RMSE=∑i=1n(Y(i)-f(x(i)))2n=SSEn" role="presentation">RMSE=√∑ni=1(Y(i)−f(x(i)))2n=√SSEnRMSE=∑i=1n(Y(i)-f(x(i)))2n=SSEn

where,

n is the total number of datapoints available.

BODY OF CONTENT:

Firstly, inserting the data points to plot the actual data curve:

clear all
close all
clc

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

%ploting the data
plot(temperature,cp,'linewidth',3)
xlabel('Temperature[K]')
ylabel('Specific heat[KJ/Kmol.K]')

plot of actual data-

For linear curve fit for the above data-

%Linear curve fit
clear all
close all
clc

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

%ploting the data
plot(temperature,cp,'linewidth',3)
xlabel('Temperature[K]')
ylabel('Specific heat[KJ/Kmol.K]')

%curvefit(linear)
%cp=a*T+b
coeffs = polyfit(temperature,cp,1);
predicted_cp = polyval(coeffs,temperature);

%compare my curve fit with original data

hold on 

plot(temperature,predicted_cp,'linewidth',3,'color','r')
xlabel('Temperature[K]')
ylabel('Specific heat[KJ/Kmol.K]')
legend('oroginal dataset','curvefit')

plot:

For cubic curve fit:

%Cubic curve fit
clear all
close all
clc

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

%ploting the data
plot(temperature,cp,'linewidth',3)
xlabel('Temperature[K]')
ylabel('Specific heat[KJ/Kmol.K]')

%curvefit(linear)
%cp=a*T^3+b*T^2+c*T+d
coeffs = polyfit(temperature,cp,3);
predicted_cp = polyval(coeffs,temperature);

%compare my curve fit with original data

hold on 

plot(temperature,predicted_cp,'linewidth',3,'color','r')
xlabel('Temperature[K]')
ylabel('Specific heat[KJ/Kmol.K]')
legend('oroginal dataset','curvefit')

plot:

To improve the curve fit, let increase the order>>

clear all
close all
clc

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

%ploting the data
plot(temperature,cp,'linewidth',3)
xlabel('Temperature[K]')
ylabel('Specific heat[KJ/Kmol.K]')

%curvefit(linear)
%cp=a*T^4+b*T^3+c*T^2+d*T+e
coeffs = polyfit(temperature,cp,4);
predicted_cp = polyval(coeffs,temperature);

%compare my curve fit with original data

hold on 

plot(temperature,predicted_cp,'linewidth',3,'color','r')
xlabel('Temperature[K]')
ylabel('Specific heat[KJ/Kmol.K]')
legend('oroginal dataset','curvefit')

Improved curve fit:

The above curve fit is showing approx same data points as the actual curve.

CODE EXPLANATION:

  • Clear all,Close all,clc command is for clear all fields in command window and close all plots etc.
  • To insert the data file "load" command is used.
  • Polyfit command: it is of form, P=polyfit(x,y,n) [fits ploynomial of order n to data in x,y] .
  • Polyval commanmd: it is of form, Q=polyval(P,x) [ P is vector of polynomial coeffs,Q is polynomial values at locations in x].
  • To name the curves "legend" command is used.

ERRORS:

1. Error in polyfit :

2.Typed 'Temperature' instead of 'temperature':

REFERENCES:

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.