Project

Fitting of curve

clear all
close all
clc

%loading data file
cp_data= load(\'data1\');
temp= cp_data(:,1);
cp=cp_data(:,2);


%cp= a*T^2 + b*T +c and a*T^3 + b*T^2 +c*T+d
coeff = polyfit(temp,cp,2);
predcp= polyval(coeff, temp);
coeff1 = polyfit(temp,cp,3);
predcp1=polyval(coeff1,temp);

%plotting
subplot(2,1,[1]);
plot(temp, cp,\'linewidth\',3);
hold on
plot(temp, predcp,\'linewidth\',3,\'color\',\'r\');
grid on
xlabel(\'temprature\')
ylabel(\'cp\')
legend(\'original curve\',\'curve fit(deg=2)\');
subplot(2,1,[2]);
plot(temp, cp,\'linewidth\',3);
hold on
plot(temp, predcp1,\'linewidth\',3,\'color\',\'r\');
grid on
xlabel(\'temprature\')
ylabel(\'cp\')
legend(\'original curve\',\'curve fit(deg=3)\');

Curve fitting is essentially taking data and building an approximate model for the data, producing a curve which is just a function. It describes the changes in data mathematically. Desrired results depend on the accuracy of curve fit. The program for curve fit is used for the speicific heat values as a function of temperature in case of oxygen, which looks as follows:

The first column consists of temperature values and second consists of Cp values.

This data is loaded in the program using load() function, for this the directory must be same.

Incase of 2nd order or linear fit (i.e a*T^2 + b*T +c), the required coefficients are extracted simply using polyfit(), by specifying input parameters of temperature, Cp and degree of arbitrary function. Predicted Cp are found using polyval() which simply means polynomial value. To display two graphs together using hold on the second curve( temp vs predicted cp) is plotted.

Same can be done for 3rd order or cubic curve fitting. For greater accuracy and less error , higher degree of polynomial is used. Hence it is easily noticable that the cubic curve is more accurate than the linear curve fit. For higher accuracy, various mathematical ways are used like:

1. Polynomial regression

2. Least square method

3. Guassian method

4 Lorentzain

Output curve obtained is as follows

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.