Curve Fitting

Download as pdf or txt
Download as pdf or txt
You are on page 1of 51

05 Curve Fitting

05 Curve Fitting
Introduction

• Data are often given for discrete values


along a continuum. However, we may
require estimates at points between the
05 Curve Fitting

discrete values.
• This Chapter describes techniques to fit
curves to such data to obtain intermediate
estimates.
• There are two general approaches for curve
fitting that are distinguished from each
other on the basis of the amount of error
05 Curve Fitting

associated with the data.


- Regression
- Interpolation
Regression

• The data exhibit a significant degree of


error, the strategy is to derive a single
curve that represents the general trend of
05 Curve Fitting

the data.
• Because any individual data point may be
incorrect, we make no effort to intersect
every point. Rather, the curve is designed to
follow the pattern of the points taken as a
group. One approach of this nature is called
least-squares regression
Interpolation

• The data are known to be very precise, the


basic approach is to fit a curve or a series of
curves that pass directly through each of the
05 Curve Fitting

points.
• Such data usually originate from tables.
Examples are values for the density of water
or for the heat capacity of gases as a
function of temperature.
• The estimation of values between well-
known discrete points is called interpolation
Three attempts to fit a
“best” curve through
five data points:
05 Curve Fitting

(a) least-squares
regression,
(b) linear interpolation,
(c) curvilinear
interpolation.
5.1. Regression
a. Linear Regression
• The primary objective of this method is to
how least-squares regression can be used to
05 Curve Fitting

fit a straight line to measured data.

The mathematical expression for the straight


line is,
y = a0 + a1x
• One strategy for fitting a “best” line through
the data would be to minimize the sum of
the residual errors for all the available data,
05 Curve Fitting

as in
Examples of some criteria
for “best fit” that are
inadequate for regression:
05 Curve Fitting

(a) minimizes the sum


of the residuals,
(b) minimizes the sum of
the absolute values of the
residuals, and
(c) minimizes the
maximum error of any
individual point.
• A strategy that overcomes the shortcomings
of the aforementioned approaches is to
minimize the sum of the squares of the
05 Curve Fitting

residuals:
• To determine values for a0 and a1, Eq. above is
differentiated with respect to each unknown coefficient:
05 Curve Fitting
• These are called the normal equations. They
can be solved simultaneously for
05 Curve Fitting
Problem

• Fit a straight line to the values in Table


14.1.
05 Curve Fitting
LINEARIZATION OF NONLINEAR
RELATIONSHIPS
• Linear regression provides a powerful
technique for fitting a best line to data.
However, it is predicated on the fact that the
05 Curve Fitting

relationship between the dependent and


independent variables is linear.
• This is not always the case, and the first
step in any regression analysis should be to
plot and visually inspect the data to
ascertain whether a linear model applies.
• In some cases, techniques such as
polynomial regression, which is described
in next sub Chap., are appropriate. For
05 Curve Fitting

others, transformations can be used to


express the data in a form that is compatible
with linear regression.
05 Curve Fitting
05 Curve Fitting b. Regresi Polinomial
05 Curve Fitting
Regresi dg Matlab
Fungsi Polyfit
Dalam Matlab, fungsi polyfit
menyelesaikan masalah pencocokan kurva
05 Curve Fitting

untuk kuadrat terkecil.


Penggunaan fungsi polyfit akan
menghasilkan suatu persamaan polinomial
yang paling mendekati data.
Jika derajat fungsi polyfit dipilih n = 1,
maka akan dihasilkan persamaan garis lurus
yaitu regresi linier.
kons = polyfit(x,y,1)
05 Curve Fitting Soal 1
Soal 2
Tekanan uap toluena pada persamaan Antoine
Data tekanan uap toluena dalam OC dan Torr adalah
05 Curve Fitting

T (OC) -26,7 -4,4 6,4 18,4 31,8 40,3

p (torr) 1 5 10 20 40 60

Tentukan konstanta-konstanta persamaan Antoine


yang menyatakan hubungan T dan p sebagai
berikut
 b 
p  exp a  
 T  273,2 
lanjutan

 b 
p  exp  a  
 T  273,2 
b
05 Curve Fitting

ln(p) = a +
T  273,2
y=a+bx
1
y = ln(p) dan x =
T  273,2
lanjutan
% Data - data
p = [ 1 5 10 20 40 60]; % C
T = [-26.7 -4.4 6.4 18.4 31.8 40.3]; % Torr
05 Curve Fitting

% Linierisasi
y = log(p);
x = 1./(T+273.15);

kons = polyfit(x,y,1);
a = kons(2)
b = kons(1)
Regresi Polinomial
data-data didekati dengan persamaan
polinomial, yaitu :
y = a0 + a1x + a2x2 + .... + amxm
05 Curve Fitting
lanjutan
Fungsi polyfit dari Matlab dapat
digunakan untuk derajat n = 2, yang disebut
polinomial kuadratis. Hasil fungsi
05 Curve Fitting

polyfit adalah vektor baris yang berisi


koefisien-koefisien polinomial.

Selain fungsi polyfit, Matlab juga


mempunyai fungsi polyval untuk
mengevaluasi polinomial pada tiap titik
yang ingin diketahui nilainya.
Soal 2
Persamaan Fit untuk Data Tekanan Uap Benzena
Data tekanan uap murni benzena pada berbagai temperatur
ditunjukkan pada tabel.
Temperatur Tekanan Temperatur Tekanan
(OC) (mmHg) (OC) (mmHg)
05 Curve Fitting

-36,7 1 15,4 60
-19,6 5 26,1 100
-11,5 10 42,2 200
-2,6 20 60,6 400
7,6 40 80,1 760
Hubungan tekanan sebagai fungsi temperatur dapat dinyatakan
sebagai persamaan empiris polinomial sederhana sebagai berikut :
P = a0 + a1T + a2T2 + a3T3 + … + anTn
dengan a0, a1, …, an adalah parameter yang ditentukan dengan regresi
dan n adalah orde polinomial.
lanjutan
vp = [ 1 5 10 20 40 60 100 200 400 760];
T =[-36.7 -19.6 -11.5 -2.6 7.6 15.4 26.1
42.2 60.6 80.1];
05 Curve Fitting

% Penggunaan fungsi polyfit


m = 3; %orde polinomial
k = polyfit(T,vp,m);
% Evaluasi persamaan polinomial
z = polyval(k,55)
lanjutan
vp = [ 1 5 10 20 40 60 100 200 400 760];
T =[-36.7 -19.6 -11.5 -2.6 7.6 15.4 26.1
42.2 60.6 80.1];
05 Curve Fitting

% Penggunaan fungsi polyfit


m = 3; %orde polinomial
k = polyfit(T,vp,m);
% Evaluasi persamaan polinomial
z = polyval(k,T);
% Cetak hasil
plot(T,z,'k-',T,vp,'ko','linewidth',2)
xlabel('T(C)')
ylabel('vp(mmHg)')
05 Curve Fitting Next meeting
05 Curve Fitting
05 Curve Fitting
• There are two general approaches for curve
fitting that are distinguished from each
other on the basis of the amount of error
05 Curve Fitting

associated with the data.


- Regression
- Interpolation
6.2. Interpolation

• Interpolation is used to estimate


intermediate values between precise data
points.
05 Curve Fitting
a. Linear Interpolation
• The simplest form of interpolation is to connect two data points with a
straight line. This technique, called linear interpolation, is depicted
graphically in Fig.
05 Curve Fitting

Newton linear-
interpolation formula.
• Find ρ, μ, and v at T = 27 oC
05 Curve Fitting
b. Quadratic Interpolation
• A strategy for improving the estimate is to introduce some
curvature into the line connecting the points. If three data
points are available, this can be accomplished with a
05 Curve Fitting

second-order polynomial (also called a quadratic


polynomial or a parabola).
05 Curve Fitting • Find ρ, μ, and v at T = 27 oC
General Form of Newton’s
Interpolating Polynomials
05 Curve Fitting
05 Curve Fitting
From data of acetic acid density at 25 OC, find the density of
acetic acid at 65 % !
05 Curve Fitting
Interpolation with Matlab
Function
interp1 for linier interpolation.
YI = interp1 (X,Y,XI,’the methode’)
05 Curve Fitting

For find Y YI if X = X1, with data Y vs X

The methode
‘nearest‘-
‘linier‘-
‘spline‘-
‘cubic‘ -
Konduktivitas termal aseton
Bennett & Meyers memberikan data-data konduktivitas
termal aseton. Hubungan ln (k) dan ln (T) mendekati
05 Curve Fitting

persamaan garis lurus, dengan T dalam R (R = OF + 460).


Tentukan nilai k pada 300 OF !
k T (OF)
[BTU/jam.ft.OF]
0,0057 32

0,0074 115

0,0099 212

0,0147 363
lanjutan
k = [0.0057 0.0074 0.0099 0.0147];
T = [32 115 212 363]+460;
% Hubungan k dan T linier
05 Curve Fitting

ln_k = log(k);
ln_T = log(T);
% Interpolasi Linier
T300 = log(300+460);
k300 = interp1(ln_T,ln_k,T300,'linier');
% Hasil
k_pd_300 = exp(k300)
b. Splines Interpolation
• nth-order polynomials were used to interpolate between
(n+1) data points.
• For example, for eight points, we can derive a perfect
05 Curve Fitting

seventh-order polynomial. This curve would capture all


the meanderings (at least up to and including seventh
derivatives) suggested by the points.
• However, there are cases where these functions can lead
to erroneous results because of round-off error and
oscillations.
• An alternative approach is to apply lower-order
polynomials in a piecewise fashion to subsets of data
points. Such connecting polynomials are called spline
functions.
• For example, third-order curves employed to
connect each pair of data points are called cubic
splines.
05 Curve Fitting

• These functions can be constructed so that the


connections between adjacent cubic equations are
visually smooth.
05 Curve Fitting
% Data parameter viskositas sebagai fungsi x
x = [0 0.1 0.2 0.3 0.4 0.5];
B1 = [-19.52 -22.14 -25.16 -28.38 -31.52 -34.51];
B2 = [3.913 4.475 5.157 5.908 6.678 7.417]*10^3;
B3 = [2.112 2.470 2.859 3.255 3.634 3.972]*10^-2;

% Data x dan T yang ingin dicari viskositasnya


x_i = 0.43; % Konsentrasi
05 Curve Fitting

T_i = 45+273.15; % Temperatur, K

% Interpolasi hubungan fraksi berat vs konstanta


% Konstanta B1, B2, dan B3 pada 0.43 ditentukan terlebih dahulu
% Interpolasi nilai B pada konsentrasi 0.43
B1_i = interp1(x,B1,x_i,'spline');
B2_i = interp1(x,B2,x_i,'spline');
B3_i = interp1(x,B3,x_i,'spline');
% Viskositas dihitung
viscA = exp(B1_i + B2_i/T_i + B3_i*T_i)

% Interpolasi hubungan fraksi berat vs viskositas


% Viscositas pada 45 C ditentukan terlebih dahulu
% Viskositas pada 45 C dihitung
visc = exp(B1 + B2./T_i + B3.*T_i)
% Interpolasi viskositas pada konsentrasi 0.43
viscB = interp1(x,visc,x_i,'spline')
c. Two dimension Interpolation
Interpolasi dua dimensi mempunyai prinsip yang
sama dengan interpolasi satu dimensi. Perbedaanya
adalah interpolasi dua dimensi menginterpolasikan
05 Curve Fitting

fungsi dua variabel z = f(x,y).

ZI = interp2 (X,Y,Z,XI,YI) adalah interpolasi untuk


menentukan nilai ZI, dari fungsi Z pada titik XI dan
YI dari matriks X dan Y. Metode yang ditampilkan
pada interpolasi 1 dimensi dapat juga digunakan
pada interpolasi 2 dimensi.
05 Curve Fitting
% Kondisi awal
To = [600 700]; % Temperatur, oF
po = [90 95]; % Tekanan, psia
Ho = [1328.7 1378.1
05 Curve Fitting

1328.4 1377.8]; % Entalphi, BTU/lb


H1 = interp2(To,po,Ho,640,92) % Interpolasi 2 dimensi

% Kondisi akhir
Tn = [400 500]; % Temperatur, oF
pn = [50 55]; % Tekanan, psia
Hn = [1258.7 1282.6
1258.2 1282.2]; % Entalphi, BTU/lb
H2 = interp2(Tn,pn,Hn,480,52) % Interpolasi 2 dimensi

% Perhitungan beda entalpi


del_H = H2 - H1
05 Curve Fitting
05 Curve Fitting

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy