SlideShare a Scribd company logo
1 of 27
Intr. to Computational Physics
ch2.
METHODS OF DATA FITTING
By Jifar R.
JU CNS Phys. Dept.
Data Fitting
• Data fitting is an art worthy of serious study. In this unit we
just scratch the surface.
• Data fitting is the process of fitting models to data and
analyzing the accuracy of the fit. Engineers and scientists
use data fitting techniques, including mathematical equations
and nonparametric methods, to model acquired data.
• We examine how to interpolate within a table of numbers
and how to do a least-squares fit for linear functions.
• If a least squares fit is needed for non linear functions, then
some of the search routines, either your own or those
obtained from scientific subroutine libraries, may be used.
Numerical interpolation and extrapolation
• is perhaps one of the most used tools in numerical
applications to physics.
• function f at a set of points x1, …xn where an analytic
form is missing,
• f may represent some data points from experiment or
result of a lengthy large-scale computation of physical
quantity that cannot be cast into a simple analytical
form,
• to evaluate f at point x within data set x1, …xn, where x
differs from the tabulated values:  interpolation
• If x is outside:  extrapolation
• Two methods of interpolation and extrapolation:
polynomial interpolation and extrapolation and qubic
spline interpolation.
• polynomial interpolation is the interpolation of a given
data set by the polynomial of lowest possible degree that
passes through the points of the dataset.
• Given a set of n + 1 data points ( 𝒙𝟎 , 𝒚𝟎 ) , … , ( 𝒙𝒏 , 𝒚𝒏 )
with no two 𝑥𝑗 the same, a polynomial function 𝑝 𝑥 is
said to interpolate the data if 𝒑 𝒙𝒊 = 𝒚𝒊 for each
𝒋 ∈ 𝟎, 𝟏, … 𝒏
• Two common explicit formulas for this polynomial are the
Lagrange polynomials and Newton polynomials.
• Two common explicit formulas for this polynomial are the
Lagrange polynomials and Newton polynomials.
• Interpolation is needed when we want to infer some local
information from a set of incomplete or discrete data.
• Overall approximation or fitting is needed when we want
to know the general or global behavior of the data.
Interpolation
• In doing measurement: discrete set of points
represent the experiment.
• Interpretation of measured data or theoretical
calculations is important part.
• Assume experiment to be represented by pairs of
values x & y:
• x is independent variable which vary,
• y is the measured value at point x, i.e. y = y(x)
• Consider a radioactive source and a detector, which
counts the number of decays.
• To determine half-life of this source, count the
number of decays 𝑁0, 𝑁1, 𝑁2, … . . . 𝑁𝑘 𝑎𝑡 𝑡𝑖𝑚𝑒 𝑡0, 𝑡1, 𝑡2, … . . . . 𝑡𝑘.
Interpolation
• t is independent variable, & what you measure is a discrete set of
pairs of numbers 𝑡𝑘, 𝑁𝑘 in the range of 𝑡0, 𝑡𝑘
• In order to extract information from such an experiment, finding
analytical function which relates N(t) & t
• sometimes finding it is impossible, or it is time consuming to
calculate(if known) or we might be only interested in a small local
region of the independent variable.
• Assume radioactive source is α emitter, Its half-life is
𝑡1 2 = 430 𝑦𝑒𝑎𝑟𝑠, cannot be determine by measuring,
• Because it is very slowly decaying you probably will measure the
activity over a longer time period, say every Monday for a couple
of months.
• After 5 months you would stop and look at the data.
• What was the activity A(t) on Wednesday of the 3rd week?
• This day is inside your range of 𝑡0, 𝑡𝑘 : use interpolation
techniques to determine this value.
Interpolation
• Again to know activity (A) 8 months from end of your
measurement, use extrapolation to this point from the
previous series of measurements.
• Idea of interpolation is to select a function 𝑔 𝑥 such that
𝑔 𝑥𝑖 = 𝑓𝑖 for each data point i and that this function is a
good approximation for any other x lying between the
original data points.
• Because data points may be interpolated by an infinite
number of functions, criterion or guideline to select a
reasonable function to get good approximation is needed.
• In mathematics there are very many theorems on function
analysis including interpolation with error analysis.
• As a rule these methods are grounded on “smoothness” of
the interpolated functions.
• This would not work for functions like 1 1 + 25𝑥2 on the
interval −1, +1 .
Linear interpolation
• For a function fi = f(xi) with i = 0, 1, . . . , n.
• Simplest approximation of f(x) for x ∈ [xi, xi+1] is
constructing straight line b/n xi and xi+1. i.e.
• which is not accurate in most cases, serves as a
good start in understanding other interpolation.
• Any value of f(x) in [xi, xi+1] is equal to the sum of
the linear interpolation in the above eqn & a
quadratic contribution that has a unique curvature
and is equal to zero at xi and xi+1.
• i.e. the error ∆f(x) in the linear interpolation is:
Linear interpolation
Between two points in straight line, b & a from eqn
𝒚 𝒙 = 𝒂 + 𝒃𝒙 are:
and
Combining them:
which is eqn of line through 𝑥1, 𝑦1 𝑥1 and 𝑥2, 𝑦2 𝑥2 .
𝒂 = 𝒚𝟏 𝒙𝟏 − 𝒙𝟏
𝒚𝟐 𝒙𝟐 − 𝒚𝟏 𝒙𝟏
𝒙𝟐 − 𝒙𝟏
𝒃 =
𝒚𝟐 𝒙𝟐 − 𝒚𝟏 𝒙𝟏
𝒙𝟐 − 𝒙𝟏
𝒚 𝒙 =
𝒙 − 𝒙𝟐
𝒙𝟏 − 𝒙𝟐
𝒚𝟏 𝒙𝟏 +
𝒙 − 𝒙𝟏
𝒙𝟐 − 𝒙𝟏
𝒚𝟐 𝒙𝟐
Quadratic interpolation
• To improve approximation result, use a second
degree polynomial and employ quadratic
interpolation:
• find 𝒂𝟏, 𝒂𝟐, 𝒂𝟑using polynomial of degree n then
replace them in y(x)
• Interpolation function:
𝒚 𝒙 = 𝒂𝟏 + 𝒂𝟐𝒙 + 𝒂𝟑𝒙𝟐
𝒚 𝒙 = 𝒂𝟏 + 𝒂𝟐 𝒙 − 𝒙𝟏 + 𝒂𝟑 𝒙 − 𝒙𝟏 𝒙 − 𝒙𝟐 ,
𝒚 𝒙 =
𝒙 − 𝒙𝟐 𝒙 − 𝒙𝟑
𝒙𝟏 − 𝒙𝟐 𝒙𝟏 − 𝒙𝟑
𝒚𝟏 𝒙𝟏 +
𝒙 − 𝒙𝟏 𝒙 − 𝒙𝟑
𝒙𝟐 − 𝒙𝟏 𝒙𝟐 − 𝒙𝟑
𝒚𝟐 𝒙𝟐 +
𝒙 − 𝒙𝟏 𝒙 − 𝒙𝟐
𝒙𝟑 − 𝒙𝟏 𝒙𝟑 − 𝒙𝟐
𝒚𝟑 𝒙𝟑
Generalized interpolation
• Using 4 points & constructing a 3rd degree
polynomial, 5 points for 4th degree and so on.
• Generalized interpolation formula passing through
n+1 data points can be derived from linear
interpolation eqn in a symmetric form with:
𝒇 𝒙 =
𝒙 − 𝒙𝒊+𝟏
𝒙𝒊 − 𝒙𝒊+𝟏
𝒇𝒊 +
𝒙 − 𝒙𝒊
𝒙𝒊+𝟏 − 𝒙𝒊
𝒇𝒊+𝟏
Example
Vapor pressure of 4He as a function of temperature
given in table. Find pressure at 3.0K.
Using linear interpolation p(3K) = 21.871kPa
Using quadratic interpolation at points 2.7, 2.9 & 3.2,
p(3K) = 21.671kPa, which is close to 21.595(exact)
Temperature [K] Vapor pressure [kPa]
2.3 6.38512
2.7 13.6218
2.9 18.676
3.2 28.2599
3.5 40.4082
3.7 49.9945
Lagrangian interpolation
• Assume we have a set of N+1 points:
y0=f(x0), y1=f(x1), y2=f(x2),…,yN=f(xN)
• To determine a polynomial of degree n so that PN(xi) =
f(xi) = yi; i=0,1,2,…N
• Write PN in the form
PN(x)=a0+a1(x-x0)+a2(x-x0)(x-x1)+…+aN(x-x0)…(x-xN-1)
The coefficients ai are determined in a recursive way,
Interpolation formulae by Lagrange and is given by:
For 2 points (a straight line) we get linear interpolation
and for 3 points we get quadratic.
The Aitken method
• One way to achieve the Lagrange interpolation
efficiently is by performing a sequence of linear
interpolations, scheme 1st developed by Aitken
(1932).
• 1st work out n linear interpolations with each
constructed from neighboring pair of n+1 data
points.
• Then use these n data points to achieve another
level of n−1 linear interpolations with the next
neighboring points of xi .
• Repeat this until we obtain the final result after n
levels of consecutive linear interpolations.
• Use equation: 𝒇𝒊...𝒋 =
𝒙 − 𝒙𝒋
𝒙𝒊 − 𝒙𝒋
𝒇𝒊...𝒋−𝟏 +
𝒙 − 𝒙𝒊
𝒙𝒋 − 𝒙𝒊
𝒇𝒊+𝟏...𝒋
Hierarchy in the Aitken scheme for n + 1 data points
Using this for 5 points: Error in the Lagrange interpolation is:
∆𝒇(𝒙) ≈
|𝒇𝟎𝟏𝟐𝟑𝟒 − 𝒇𝟎𝟏𝟐𝟑| + |𝒇𝟎𝟏𝟐𝟑𝟒 − 𝒇𝟏𝟐𝟑𝟒|
𝟐
x0 f0
f01
x1 f1 f012
f12 f0123
x2 f2 f123 f01234
f23 f1234
x3 f3 f234
f34
x4 f4
𝒇𝒊...𝒋 =
𝒙 − 𝒙𝒋
𝒙𝒊 − 𝒙𝒋
𝒇𝒊...𝒋−𝟏 +
𝒙 − 𝒙𝒊
𝒙𝒋 − 𝒙𝒊
𝒇𝒊+𝟏...𝒋
Least square fitting
To fit the curve
𝒚 = 𝒂𝒙𝒎 + 𝒃𝒙𝒎−𝟏 + 𝒄𝒙𝒎−𝟐+. , . , . +𝒈
to a given set of observations (𝑥1, 𝑦1), (𝑥2, 𝑦2), . , . , (𝑥𝑛, 𝑦𝑛)
For any 𝑥𝑖, observed value is 𝑦𝑖 and expected value is
𝜼𝒊 = 𝒂𝒙𝒏
𝒎 + 𝒃𝒙𝒏−𝟏
𝒎−𝟏
+ 𝒄𝒙𝒏−𝟐
𝒎−𝟐
+. , . , . +𝒈
Error 𝒆𝒊 = 𝒚𝒊 − 𝜼𝒊.
Sum of the squares of these errors is:
𝑬 = 𝒆𝟏
𝟐
+ 𝒆𝟐
𝟐
+ 𝒆𝟑
𝟐
+. . . +𝒆𝒏
𝟐 = 𝒆𝒊
𝟐
𝑵
𝒊=𝟏
For E to be minimum:
𝝏𝑬
𝝏𝒂
= 𝟎,
𝝏𝑬
𝝏𝒃
= 𝟎,
𝝏𝑬
𝝏𝒄
= 𝟎, , ,
𝝏𝑬
𝝏𝒈
= 𝟎
Linear Least Square fitting
Working procedure
To fit the straight line y = ax + b,
𝜂𝑖 = 𝑎𝑥𝑖 + 𝑏
𝑒𝑖 = 𝑦𝑖 − 𝜂𝑖
𝑬 = 𝒆𝒊
𝟐
𝑵
𝒊=𝟏
For E to be minimum:
𝝏𝑬
𝝏𝒂
= 𝟎,
𝝏𝑬
𝝏𝒃
= 𝟎
If the given data points are five; n=5
𝑒1 = 𝑦1 − 𝜂1 = 𝑦1 − (𝑎𝑥1 + 𝑏)
𝑒2 = 𝑦2 − 𝜂2 = 𝑦2 − (𝑎𝑥2 + 𝑏)
𝑒3 = 𝑦3 − 𝜂2 = 𝑦3 − (𝑎𝑥3 + 𝑏)
𝑒4 = 𝑦4 − 𝜂4 = 𝑦4 − (𝑎𝑥4 + 𝑏)
𝑒5 = 𝑦5 − 𝜂5 = 𝑦5 − (𝑎𝑥5 + 𝑏)
𝐸 = 𝑒1
2
+ 𝑒2
2
+ 𝑒3
2
+ 𝑒4
2
+ 𝑒5
2
Adding terms of the same type gives:
𝑎 𝑥𝑖
2
𝑛
𝑖=1
+ 𝑏 𝑥𝑖 = 𝑥𝑖𝑦𝑖
𝑛
𝑖=1
𝑎 𝑥𝑖
𝑛
𝑖=1
+ 𝑏𝑛 = 𝑦𝑖
𝑛
𝑖=1
• The above eqns are Normal equations,
• solved simultaneously in a and b.
• a & b when substituted give desired curve of best fit
𝑎 =
𝑛 𝑥𝑖𝑦𝑖
𝑖 − 𝑥𝑖
𝑖 𝑦𝑖
𝑖
𝑛 𝑥𝑖
2
𝑖 − 𝑥𝑖
𝑖 𝑥𝑖
𝑖
and 𝑏 =
𝑛 𝑥𝑖
2
𝑖 𝑦𝑖
𝑖 − 𝑥𝑖
𝑖 𝑥𝑖
𝑖 𝑦𝑖
𝑛 𝑥𝑖
2
𝑖 − 𝑥𝑖
𝑖 𝑥𝑖
𝑖
Example
An experiment produces the following data sample pairs
(xi , yi ): y = ax + b, find a & b
xi = 1.85,2.72,2.81,3.06,3.42,3.76,4.31,4.47,4.64,4.99
yi = 2.26,3.10,3.80,4.11,4.74,4.31,5.24,4.03,5.69,6.57
Step 1. determine each sum, n=10
𝑥 = 36.03, 𝑦 = 43.85, 𝑥𝑦 = 168.06839, 𝑥2
= 138.90129
Step 2. use these values in the equations of a and b
• value of slope is a = 1.1091495
• value of intercept is b = 0.38873413
Cubic Spline fitting
• Over n intervals, the routine fits n equations subject
to the boundary conditions of n+1 data points.
• Derivation assumes functional form for the curve
fit.
• This equation form is simplified and then solved for
the curve fit equation.
• The assumed form for the cubic polynomial curve
fit for each segment is,
• Spacing between successive data points is
Cubic Spline fitting
• Cubic spline constrains the function value, 1st & 2nd
derivative.
• The routine must ensure that y(x), y′(x), and y′′(x)
and are equal at interior node points for adjacent
segments.
• Substituting a variable S for the polynomial’s 2nd
derivative reduces number of eqns from a, b, c, d for
each segment to only S for each segment.
• For ith segment, the S governing equation is,
Cubic Spline fitting
• In matrix form, governing eqns reduce to tri-diagonal.
• S1= Sn= 0 for natural spline boundary condition.
• Substituting the above into a, b, c and d correspond to the
polynomial definition for each segment.
General program steps
• Problem Initialization: program initializes the
variables.
• Read in Data Values: data values are read and the
individual intervals are calculated.
• Determine S matrices: influence coefficient values for
S are determined. The constant matrix, C, is determined.
• Matrix Solver: Tri-Diagonal-Matrix-Algorithm
determines the S value at each interval.
• Calculate Cubic Parameters: cubic parameters a, b, c
and d are calculated at each interval from S and h.
• Write out: The program writes out the polynomial
specification terms a, b, c and d.
F90 program for cubic spline interpolation
Program cubic_spline
Implicit none
! Initialization
Real*8, Dimension (10):: x, y, h
Integer :: norder, i, j , ntdma, nstep, step
Real*8, Dimension (10):: S, B, D, A, C
Real*8 R,xx(10),yy(10), xs, ys
Integer, parameter::n=100,m=1000
Real*8 xr(m), yr(m), xa(m), fa(m), dx
!Read in data-point order
norder = 5
!x=0,1,2,3,4: 5 data points
do i=1,norder
y(i) = x(i)**3 -8.0
End do
! width of the ith interval
Do i = 1, (norder - 1)
h(i) = x(i + 1) - x(i)
End do
! Set S matrix for natural spline
Do i = 2 , (norder - 1)
j = i - 1
D (j) = 2 * (h(i - 1) + h(i))
A(j) = h(i) !Ignore A(norder)
B(j) = h(i - 1) !Ignore B(0)
End do
!Set Constant Matrix C
Do i = 2 , (norder - 1)
j = i - 1
C(j)=6*((y(i+1)-y(i))/h(i) - (y(i) - y(i - 1)) / h(i -
1))
End do
! Max tdma length
ntdma = norder - 2
!Upper Triangularization
Do i = 2 , ntdma
R = B(i) / D(i - 1)
D(i) = D(i) - R * A(i - 1)
C(i) = C(i) - R * C(i - 1)
End do
! Directly set the last C
C(ntdma) = C(ntdma)/D(ntdma)
! Back Substitute
Do i = (ntdma - 1) , 1, -1
C(i) = (C(i) - A(i) * C(i + 1)) / D(i)
End do
! Switch from C to S
Do i = 2 , (norder - 1)
j = i - 1 ! Shift from TDMA coordinate system
S(i) = C(j)
End do
S(1) = 0.0
S(norder) = 0.0
! Calculate cubic ai,bi,ci and di from S and h
Do i = 1 , (norder - 1)
A(i) = (S(i + 1) - S(i)) / (6 * h(i))
B(i) = S(i) / 2.
C(i) = (y(i + 1)-y(i))/h(i)-(2 * h(i) * S(i) + h(i) * S(i
+ 1))/6.
D(i) = y(i)
End do
Do i = 1 , norder
End do
Plotting
! Read in steps
nstep = 100
step = 0
Do i = 1 , (norder - 1) !'Discrete function
Do j = 1 , nstep
step = step + 1
xs = x(i) + (h(i) / nstep) * (j - 1)
ys=A(i)*(xs - x(i))**3 + B(i)*(xs - x(i))**2 +
C(i)*(xs - x(i)) + D(i)
xr(step) = xs
yr(step) = ys
End do
End do
do i=1,step
!print*,i,xr(i),yr(i)
write(1,*)xr(i),yr(i)
enddo
End
• fit is good except b/n x=3 & 4
w/c is caused by natural spline
boundary conditions at x=0 & 4.
• Changing the spline to reflect the
correct 2nd derivative at x=4
would help the fit.

More Related Content

What's hot

2. polynomial interpolation
2. polynomial interpolation2. polynomial interpolation
2. polynomial interpolationEasyStudy3
 
Lesson 21: More Algebra
Lesson 21: More AlgebraLesson 21: More Algebra
Lesson 21: More AlgebraKevin Johnson
 
MCA_UNIT-1_Computer Oriented Numerical Statistical Methods
MCA_UNIT-1_Computer Oriented Numerical Statistical MethodsMCA_UNIT-1_Computer Oriented Numerical Statistical Methods
MCA_UNIT-1_Computer Oriented Numerical Statistical MethodsRai University
 
Indefinite Integral
Indefinite IntegralIndefinite Integral
Indefinite IntegralRich Elle
 
A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...
A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...
A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...ijfls
 
Lesson 11: Functions and Function Notation
Lesson 11: Functions and Function NotationLesson 11: Functions and Function Notation
Lesson 11: Functions and Function NotationKevin Johnson
 
More theorems on polynomial functions
More theorems on polynomial functionsMore theorems on polynomial functions
More theorems on polynomial functionsLeo Crisologo
 
Perspective in Informatics 3 - Assignment 1 - Answer Sheet
Perspective in Informatics 3 - Assignment 1 - Answer SheetPerspective in Informatics 3 - Assignment 1 - Answer Sheet
Perspective in Informatics 3 - Assignment 1 - Answer SheetHoang Nguyen Phong
 
Theorems on polynomial functions
Theorems on polynomial functionsTheorems on polynomial functions
Theorems on polynomial functionsLeo Crisologo
 
A NEW OPERATION ON HEXAGONAL FUZZY NUMBER
A NEW OPERATION ON HEXAGONAL FUZZY NUMBERA NEW OPERATION ON HEXAGONAL FUZZY NUMBER
A NEW OPERATION ON HEXAGONAL FUZZY NUMBERijfls
 
Math 4 graphing rational functions
Math 4 graphing rational functionsMath 4 graphing rational functions
Math 4 graphing rational functionsLeo Crisologo
 
MCA_UNIT-2_Computer Oriented Numerical Statistical Methods
MCA_UNIT-2_Computer Oriented Numerical Statistical MethodsMCA_UNIT-2_Computer Oriented Numerical Statistical Methods
MCA_UNIT-2_Computer Oriented Numerical Statistical MethodsRai University
 

What's hot (19)

2. polynomial interpolation
2. polynomial interpolation2. polynomial interpolation
2. polynomial interpolation
 
Lesson 21: More Algebra
Lesson 21: More AlgebraLesson 21: More Algebra
Lesson 21: More Algebra
 
MCA_UNIT-1_Computer Oriented Numerical Statistical Methods
MCA_UNIT-1_Computer Oriented Numerical Statistical MethodsMCA_UNIT-1_Computer Oriented Numerical Statistical Methods
MCA_UNIT-1_Computer Oriented Numerical Statistical Methods
 
Indefinite Integral
Indefinite IntegralIndefinite Integral
Indefinite Integral
 
Curve fitting
Curve fittingCurve fitting
Curve fitting
 
Project2
Project2Project2
Project2
 
A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...
A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...
A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...
 
Lesson 11: Functions and Function Notation
Lesson 11: Functions and Function NotationLesson 11: Functions and Function Notation
Lesson 11: Functions and Function Notation
 
More theorems on polynomial functions
More theorems on polynomial functionsMore theorems on polynomial functions
More theorems on polynomial functions
 
Numerical method (curve fitting)
Numerical method (curve fitting)Numerical method (curve fitting)
Numerical method (curve fitting)
 
Perspective in Informatics 3 - Assignment 1 - Answer Sheet
Perspective in Informatics 3 - Assignment 1 - Answer SheetPerspective in Informatics 3 - Assignment 1 - Answer Sheet
Perspective in Informatics 3 - Assignment 1 - Answer Sheet
 
Theorems on polynomial functions
Theorems on polynomial functionsTheorems on polynomial functions
Theorems on polynomial functions
 
Fst ch3 notes
Fst ch3 notesFst ch3 notes
Fst ch3 notes
 
Pattern Discovery - part I
Pattern Discovery - part IPattern Discovery - part I
Pattern Discovery - part I
 
A NEW OPERATION ON HEXAGONAL FUZZY NUMBER
A NEW OPERATION ON HEXAGONAL FUZZY NUMBERA NEW OPERATION ON HEXAGONAL FUZZY NUMBER
A NEW OPERATION ON HEXAGONAL FUZZY NUMBER
 
Math 4 graphing rational functions
Math 4 graphing rational functionsMath 4 graphing rational functions
Math 4 graphing rational functions
 
Q0749397
Q0749397Q0749397
Q0749397
 
MCA_UNIT-2_Computer Oriented Numerical Statistical Methods
MCA_UNIT-2_Computer Oriented Numerical Statistical MethodsMCA_UNIT-2_Computer Oriented Numerical Statistical Methods
MCA_UNIT-2_Computer Oriented Numerical Statistical Methods
 
Integral calculus
Integral calculusIntegral calculus
Integral calculus
 

Similar to Intro. to computational Physics ch2.pdf

Interpolation(2) Numerical methods to CE Problems).pdf
Interpolation(2) Numerical methods to CE Problems).pdfInterpolation(2) Numerical methods to CE Problems).pdf
Interpolation(2) Numerical methods to CE Problems).pdfAlyzaCaszyUmayat
 
Lagrange Interpolation
Lagrange InterpolationLagrange Interpolation
Lagrange InterpolationSaloni Singhal
 
Unit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxUnit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxssuser01e301
 
Elements of Statistical Learning 読み会 第2章
Elements of Statistical Learning 読み会 第2章Elements of Statistical Learning 読み会 第2章
Elements of Statistical Learning 読み会 第2章Tsuyoshi Sakama
 
Numerical differentiation and integration
Numerical differentiation and integrationNumerical differentiation and integration
Numerical differentiation and integrationBektu Dida
 
PRESENT.pptx this paper will help the next
PRESENT.pptx this paper will help the nextPRESENT.pptx this paper will help the next
PRESENT.pptx this paper will help the nextseidnegash1
 
Optimum Engineering Design - Day 2b. Classical Optimization methods
Optimum Engineering Design - Day 2b. Classical Optimization methodsOptimum Engineering Design - Day 2b. Classical Optimization methods
Optimum Engineering Design - Day 2b. Classical Optimization methodsSantiagoGarridoBulln
 
Chapter 1 - What is a Function.pdf
Chapter 1 - What is a Function.pdfChapter 1 - What is a Function.pdf
Chapter 1 - What is a Function.pdfManarKareem1
 
Lesson 10 techniques of integration
Lesson 10 techniques of integrationLesson 10 techniques of integration
Lesson 10 techniques of integrationLawrence De Vera
 
Lecture 01-2 (Functions).pptx
Lecture 01-2 (Functions).pptxLecture 01-2 (Functions).pptx
Lecture 01-2 (Functions).pptxÅįjâž Ali
 
Open newton cotes quadrature with midpoint derivative for integration of al...
Open newton   cotes quadrature with midpoint derivative for integration of al...Open newton   cotes quadrature with midpoint derivative for integration of al...
Open newton cotes quadrature with midpoint derivative for integration of al...eSAT Journals
 
Opt Assgnment #-1 PPTX.pptx
Opt Assgnment #-1 PPTX.pptxOpt Assgnment #-1 PPTX.pptx
Opt Assgnment #-1 PPTX.pptxAbdellaKarime
 
Linear regression, costs & gradient descent
Linear regression, costs & gradient descentLinear regression, costs & gradient descent
Linear regression, costs & gradient descentRevanth Kumar
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesSreedhar Chowdam
 

Similar to Intro. to computational Physics ch2.pdf (20)

Chapter two
Chapter twoChapter two
Chapter two
 
Curve fitting
Curve fittingCurve fitting
Curve fitting
 
Interpolation(2) Numerical methods to CE Problems).pdf
Interpolation(2) Numerical methods to CE Problems).pdfInterpolation(2) Numerical methods to CE Problems).pdf
Interpolation(2) Numerical methods to CE Problems).pdf
 
Lagrange Interpolation
Lagrange InterpolationLagrange Interpolation
Lagrange Interpolation
 
Unit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxUnit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptx
 
Elements of Statistical Learning 読み会 第2章
Elements of Statistical Learning 読み会 第2章Elements of Statistical Learning 読み会 第2章
Elements of Statistical Learning 読み会 第2章
 
Curve Fitting
Curve FittingCurve Fitting
Curve Fitting
 
Numerical differentiation and integration
Numerical differentiation and integrationNumerical differentiation and integration
Numerical differentiation and integration
 
Scalable k-means plus plus
Scalable k-means plus plusScalable k-means plus plus
Scalable k-means plus plus
 
Unit v
Unit vUnit v
Unit v
 
PRESENT.pptx this paper will help the next
PRESENT.pptx this paper will help the nextPRESENT.pptx this paper will help the next
PRESENT.pptx this paper will help the next
 
Optimum Engineering Design - Day 2b. Classical Optimization methods
Optimum Engineering Design - Day 2b. Classical Optimization methodsOptimum Engineering Design - Day 2b. Classical Optimization methods
Optimum Engineering Design - Day 2b. Classical Optimization methods
 
Chapter 1 - What is a Function.pdf
Chapter 1 - What is a Function.pdfChapter 1 - What is a Function.pdf
Chapter 1 - What is a Function.pdf
 
Lesson 10 techniques of integration
Lesson 10 techniques of integrationLesson 10 techniques of integration
Lesson 10 techniques of integration
 
Lecture 01-2 (Functions).pptx
Lecture 01-2 (Functions).pptxLecture 01-2 (Functions).pptx
Lecture 01-2 (Functions).pptx
 
Open newton cotes quadrature with midpoint derivative for integration of al...
Open newton   cotes quadrature with midpoint derivative for integration of al...Open newton   cotes quadrature with midpoint derivative for integration of al...
Open newton cotes quadrature with midpoint derivative for integration of al...
 
Opt Assgnment #-1 PPTX.pptx
Opt Assgnment #-1 PPTX.pptxOpt Assgnment #-1 PPTX.pptx
Opt Assgnment #-1 PPTX.pptx
 
Linear regression, costs & gradient descent
Linear regression, costs & gradient descentLinear regression, costs & gradient descent
Linear regression, costs & gradient descent
 
CALCULUS 2.pptx
CALCULUS 2.pptxCALCULUS 2.pptx
CALCULUS 2.pptx
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
 

Recently uploaded

Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesSHIVANANDaRV
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of PlayPooky Knightsmith
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 

Recently uploaded (20)

Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 

Intro. to computational Physics ch2.pdf

  • 1. Intr. to Computational Physics ch2. METHODS OF DATA FITTING By Jifar R. JU CNS Phys. Dept.
  • 2. Data Fitting • Data fitting is an art worthy of serious study. In this unit we just scratch the surface. • Data fitting is the process of fitting models to data and analyzing the accuracy of the fit. Engineers and scientists use data fitting techniques, including mathematical equations and nonparametric methods, to model acquired data. • We examine how to interpolate within a table of numbers and how to do a least-squares fit for linear functions. • If a least squares fit is needed for non linear functions, then some of the search routines, either your own or those obtained from scientific subroutine libraries, may be used.
  • 3. Numerical interpolation and extrapolation • is perhaps one of the most used tools in numerical applications to physics. • function f at a set of points x1, …xn where an analytic form is missing, • f may represent some data points from experiment or result of a lengthy large-scale computation of physical quantity that cannot be cast into a simple analytical form, • to evaluate f at point x within data set x1, …xn, where x differs from the tabulated values:  interpolation • If x is outside:  extrapolation • Two methods of interpolation and extrapolation: polynomial interpolation and extrapolation and qubic spline interpolation.
  • 4. • polynomial interpolation is the interpolation of a given data set by the polynomial of lowest possible degree that passes through the points of the dataset. • Given a set of n + 1 data points ( 𝒙𝟎 , 𝒚𝟎 ) , … , ( 𝒙𝒏 , 𝒚𝒏 ) with no two 𝑥𝑗 the same, a polynomial function 𝑝 𝑥 is said to interpolate the data if 𝒑 𝒙𝒊 = 𝒚𝒊 for each 𝒋 ∈ 𝟎, 𝟏, … 𝒏 • Two common explicit formulas for this polynomial are the Lagrange polynomials and Newton polynomials. • Two common explicit formulas for this polynomial are the Lagrange polynomials and Newton polynomials. • Interpolation is needed when we want to infer some local information from a set of incomplete or discrete data. • Overall approximation or fitting is needed when we want to know the general or global behavior of the data.
  • 5. Interpolation • In doing measurement: discrete set of points represent the experiment. • Interpretation of measured data or theoretical calculations is important part. • Assume experiment to be represented by pairs of values x & y: • x is independent variable which vary, • y is the measured value at point x, i.e. y = y(x) • Consider a radioactive source and a detector, which counts the number of decays. • To determine half-life of this source, count the number of decays 𝑁0, 𝑁1, 𝑁2, … . . . 𝑁𝑘 𝑎𝑡 𝑡𝑖𝑚𝑒 𝑡0, 𝑡1, 𝑡2, … . . . . 𝑡𝑘.
  • 6. Interpolation • t is independent variable, & what you measure is a discrete set of pairs of numbers 𝑡𝑘, 𝑁𝑘 in the range of 𝑡0, 𝑡𝑘 • In order to extract information from such an experiment, finding analytical function which relates N(t) & t • sometimes finding it is impossible, or it is time consuming to calculate(if known) or we might be only interested in a small local region of the independent variable. • Assume radioactive source is α emitter, Its half-life is 𝑡1 2 = 430 𝑦𝑒𝑎𝑟𝑠, cannot be determine by measuring, • Because it is very slowly decaying you probably will measure the activity over a longer time period, say every Monday for a couple of months. • After 5 months you would stop and look at the data. • What was the activity A(t) on Wednesday of the 3rd week? • This day is inside your range of 𝑡0, 𝑡𝑘 : use interpolation techniques to determine this value.
  • 7. Interpolation • Again to know activity (A) 8 months from end of your measurement, use extrapolation to this point from the previous series of measurements. • Idea of interpolation is to select a function 𝑔 𝑥 such that 𝑔 𝑥𝑖 = 𝑓𝑖 for each data point i and that this function is a good approximation for any other x lying between the original data points. • Because data points may be interpolated by an infinite number of functions, criterion or guideline to select a reasonable function to get good approximation is needed. • In mathematics there are very many theorems on function analysis including interpolation with error analysis. • As a rule these methods are grounded on “smoothness” of the interpolated functions. • This would not work for functions like 1 1 + 25𝑥2 on the interval −1, +1 .
  • 8. Linear interpolation • For a function fi = f(xi) with i = 0, 1, . . . , n. • Simplest approximation of f(x) for x ∈ [xi, xi+1] is constructing straight line b/n xi and xi+1. i.e. • which is not accurate in most cases, serves as a good start in understanding other interpolation. • Any value of f(x) in [xi, xi+1] is equal to the sum of the linear interpolation in the above eqn & a quadratic contribution that has a unique curvature and is equal to zero at xi and xi+1. • i.e. the error ∆f(x) in the linear interpolation is:
  • 9. Linear interpolation Between two points in straight line, b & a from eqn 𝒚 𝒙 = 𝒂 + 𝒃𝒙 are: and Combining them: which is eqn of line through 𝑥1, 𝑦1 𝑥1 and 𝑥2, 𝑦2 𝑥2 . 𝒂 = 𝒚𝟏 𝒙𝟏 − 𝒙𝟏 𝒚𝟐 𝒙𝟐 − 𝒚𝟏 𝒙𝟏 𝒙𝟐 − 𝒙𝟏 𝒃 = 𝒚𝟐 𝒙𝟐 − 𝒚𝟏 𝒙𝟏 𝒙𝟐 − 𝒙𝟏 𝒚 𝒙 = 𝒙 − 𝒙𝟐 𝒙𝟏 − 𝒙𝟐 𝒚𝟏 𝒙𝟏 + 𝒙 − 𝒙𝟏 𝒙𝟐 − 𝒙𝟏 𝒚𝟐 𝒙𝟐
  • 10. Quadratic interpolation • To improve approximation result, use a second degree polynomial and employ quadratic interpolation: • find 𝒂𝟏, 𝒂𝟐, 𝒂𝟑using polynomial of degree n then replace them in y(x) • Interpolation function: 𝒚 𝒙 = 𝒂𝟏 + 𝒂𝟐𝒙 + 𝒂𝟑𝒙𝟐 𝒚 𝒙 = 𝒂𝟏 + 𝒂𝟐 𝒙 − 𝒙𝟏 + 𝒂𝟑 𝒙 − 𝒙𝟏 𝒙 − 𝒙𝟐 , 𝒚 𝒙 = 𝒙 − 𝒙𝟐 𝒙 − 𝒙𝟑 𝒙𝟏 − 𝒙𝟐 𝒙𝟏 − 𝒙𝟑 𝒚𝟏 𝒙𝟏 + 𝒙 − 𝒙𝟏 𝒙 − 𝒙𝟑 𝒙𝟐 − 𝒙𝟏 𝒙𝟐 − 𝒙𝟑 𝒚𝟐 𝒙𝟐 + 𝒙 − 𝒙𝟏 𝒙 − 𝒙𝟐 𝒙𝟑 − 𝒙𝟏 𝒙𝟑 − 𝒙𝟐 𝒚𝟑 𝒙𝟑
  • 11. Generalized interpolation • Using 4 points & constructing a 3rd degree polynomial, 5 points for 4th degree and so on. • Generalized interpolation formula passing through n+1 data points can be derived from linear interpolation eqn in a symmetric form with: 𝒇 𝒙 = 𝒙 − 𝒙𝒊+𝟏 𝒙𝒊 − 𝒙𝒊+𝟏 𝒇𝒊 + 𝒙 − 𝒙𝒊 𝒙𝒊+𝟏 − 𝒙𝒊 𝒇𝒊+𝟏
  • 12. Example Vapor pressure of 4He as a function of temperature given in table. Find pressure at 3.0K. Using linear interpolation p(3K) = 21.871kPa Using quadratic interpolation at points 2.7, 2.9 & 3.2, p(3K) = 21.671kPa, which is close to 21.595(exact) Temperature [K] Vapor pressure [kPa] 2.3 6.38512 2.7 13.6218 2.9 18.676 3.2 28.2599 3.5 40.4082 3.7 49.9945
  • 13. Lagrangian interpolation • Assume we have a set of N+1 points: y0=f(x0), y1=f(x1), y2=f(x2),…,yN=f(xN) • To determine a polynomial of degree n so that PN(xi) = f(xi) = yi; i=0,1,2,…N • Write PN in the form PN(x)=a0+a1(x-x0)+a2(x-x0)(x-x1)+…+aN(x-x0)…(x-xN-1) The coefficients ai are determined in a recursive way, Interpolation formulae by Lagrange and is given by: For 2 points (a straight line) we get linear interpolation and for 3 points we get quadratic.
  • 14. The Aitken method • One way to achieve the Lagrange interpolation efficiently is by performing a sequence of linear interpolations, scheme 1st developed by Aitken (1932). • 1st work out n linear interpolations with each constructed from neighboring pair of n+1 data points. • Then use these n data points to achieve another level of n−1 linear interpolations with the next neighboring points of xi . • Repeat this until we obtain the final result after n levels of consecutive linear interpolations. • Use equation: 𝒇𝒊...𝒋 = 𝒙 − 𝒙𝒋 𝒙𝒊 − 𝒙𝒋 𝒇𝒊...𝒋−𝟏 + 𝒙 − 𝒙𝒊 𝒙𝒋 − 𝒙𝒊 𝒇𝒊+𝟏...𝒋
  • 15. Hierarchy in the Aitken scheme for n + 1 data points Using this for 5 points: Error in the Lagrange interpolation is: ∆𝒇(𝒙) ≈ |𝒇𝟎𝟏𝟐𝟑𝟒 − 𝒇𝟎𝟏𝟐𝟑| + |𝒇𝟎𝟏𝟐𝟑𝟒 − 𝒇𝟏𝟐𝟑𝟒| 𝟐 x0 f0 f01 x1 f1 f012 f12 f0123 x2 f2 f123 f01234 f23 f1234 x3 f3 f234 f34 x4 f4 𝒇𝒊...𝒋 = 𝒙 − 𝒙𝒋 𝒙𝒊 − 𝒙𝒋 𝒇𝒊...𝒋−𝟏 + 𝒙 − 𝒙𝒊 𝒙𝒋 − 𝒙𝒊 𝒇𝒊+𝟏...𝒋
  • 16. Least square fitting To fit the curve 𝒚 = 𝒂𝒙𝒎 + 𝒃𝒙𝒎−𝟏 + 𝒄𝒙𝒎−𝟐+. , . , . +𝒈 to a given set of observations (𝑥1, 𝑦1), (𝑥2, 𝑦2), . , . , (𝑥𝑛, 𝑦𝑛) For any 𝑥𝑖, observed value is 𝑦𝑖 and expected value is 𝜼𝒊 = 𝒂𝒙𝒏 𝒎 + 𝒃𝒙𝒏−𝟏 𝒎−𝟏 + 𝒄𝒙𝒏−𝟐 𝒎−𝟐 +. , . , . +𝒈 Error 𝒆𝒊 = 𝒚𝒊 − 𝜼𝒊. Sum of the squares of these errors is: 𝑬 = 𝒆𝟏 𝟐 + 𝒆𝟐 𝟐 + 𝒆𝟑 𝟐 +. . . +𝒆𝒏 𝟐 = 𝒆𝒊 𝟐 𝑵 𝒊=𝟏 For E to be minimum: 𝝏𝑬 𝝏𝒂 = 𝟎, 𝝏𝑬 𝝏𝒃 = 𝟎, 𝝏𝑬 𝝏𝒄 = 𝟎, , , 𝝏𝑬 𝝏𝒈 = 𝟎
  • 17. Linear Least Square fitting Working procedure To fit the straight line y = ax + b, 𝜂𝑖 = 𝑎𝑥𝑖 + 𝑏 𝑒𝑖 = 𝑦𝑖 − 𝜂𝑖 𝑬 = 𝒆𝒊 𝟐 𝑵 𝒊=𝟏 For E to be minimum: 𝝏𝑬 𝝏𝒂 = 𝟎, 𝝏𝑬 𝝏𝒃 = 𝟎
  • 18. If the given data points are five; n=5 𝑒1 = 𝑦1 − 𝜂1 = 𝑦1 − (𝑎𝑥1 + 𝑏) 𝑒2 = 𝑦2 − 𝜂2 = 𝑦2 − (𝑎𝑥2 + 𝑏) 𝑒3 = 𝑦3 − 𝜂2 = 𝑦3 − (𝑎𝑥3 + 𝑏) 𝑒4 = 𝑦4 − 𝜂4 = 𝑦4 − (𝑎𝑥4 + 𝑏) 𝑒5 = 𝑦5 − 𝜂5 = 𝑦5 − (𝑎𝑥5 + 𝑏) 𝐸 = 𝑒1 2 + 𝑒2 2 + 𝑒3 2 + 𝑒4 2 + 𝑒5 2 Adding terms of the same type gives: 𝑎 𝑥𝑖 2 𝑛 𝑖=1 + 𝑏 𝑥𝑖 = 𝑥𝑖𝑦𝑖 𝑛 𝑖=1 𝑎 𝑥𝑖 𝑛 𝑖=1 + 𝑏𝑛 = 𝑦𝑖 𝑛 𝑖=1
  • 19. • The above eqns are Normal equations, • solved simultaneously in a and b. • a & b when substituted give desired curve of best fit 𝑎 = 𝑛 𝑥𝑖𝑦𝑖 𝑖 − 𝑥𝑖 𝑖 𝑦𝑖 𝑖 𝑛 𝑥𝑖 2 𝑖 − 𝑥𝑖 𝑖 𝑥𝑖 𝑖 and 𝑏 = 𝑛 𝑥𝑖 2 𝑖 𝑦𝑖 𝑖 − 𝑥𝑖 𝑖 𝑥𝑖 𝑖 𝑦𝑖 𝑛 𝑥𝑖 2 𝑖 − 𝑥𝑖 𝑖 𝑥𝑖 𝑖
  • 20. Example An experiment produces the following data sample pairs (xi , yi ): y = ax + b, find a & b xi = 1.85,2.72,2.81,3.06,3.42,3.76,4.31,4.47,4.64,4.99 yi = 2.26,3.10,3.80,4.11,4.74,4.31,5.24,4.03,5.69,6.57 Step 1. determine each sum, n=10 𝑥 = 36.03, 𝑦 = 43.85, 𝑥𝑦 = 168.06839, 𝑥2 = 138.90129 Step 2. use these values in the equations of a and b • value of slope is a = 1.1091495 • value of intercept is b = 0.38873413
  • 21. Cubic Spline fitting • Over n intervals, the routine fits n equations subject to the boundary conditions of n+1 data points. • Derivation assumes functional form for the curve fit. • This equation form is simplified and then solved for the curve fit equation. • The assumed form for the cubic polynomial curve fit for each segment is, • Spacing between successive data points is
  • 22. Cubic Spline fitting • Cubic spline constrains the function value, 1st & 2nd derivative. • The routine must ensure that y(x), y′(x), and y′′(x) and are equal at interior node points for adjacent segments. • Substituting a variable S for the polynomial’s 2nd derivative reduces number of eqns from a, b, c, d for each segment to only S for each segment. • For ith segment, the S governing equation is,
  • 23. Cubic Spline fitting • In matrix form, governing eqns reduce to tri-diagonal. • S1= Sn= 0 for natural spline boundary condition. • Substituting the above into a, b, c and d correspond to the polynomial definition for each segment.
  • 24. General program steps • Problem Initialization: program initializes the variables. • Read in Data Values: data values are read and the individual intervals are calculated. • Determine S matrices: influence coefficient values for S are determined. The constant matrix, C, is determined. • Matrix Solver: Tri-Diagonal-Matrix-Algorithm determines the S value at each interval. • Calculate Cubic Parameters: cubic parameters a, b, c and d are calculated at each interval from S and h. • Write out: The program writes out the polynomial specification terms a, b, c and d.
  • 25. F90 program for cubic spline interpolation Program cubic_spline Implicit none ! Initialization Real*8, Dimension (10):: x, y, h Integer :: norder, i, j , ntdma, nstep, step Real*8, Dimension (10):: S, B, D, A, C Real*8 R,xx(10),yy(10), xs, ys Integer, parameter::n=100,m=1000 Real*8 xr(m), yr(m), xa(m), fa(m), dx !Read in data-point order norder = 5 !x=0,1,2,3,4: 5 data points do i=1,norder y(i) = x(i)**3 -8.0 End do ! width of the ith interval Do i = 1, (norder - 1) h(i) = x(i + 1) - x(i) End do ! Set S matrix for natural spline Do i = 2 , (norder - 1) j = i - 1 D (j) = 2 * (h(i - 1) + h(i)) A(j) = h(i) !Ignore A(norder) B(j) = h(i - 1) !Ignore B(0) End do
  • 26. !Set Constant Matrix C Do i = 2 , (norder - 1) j = i - 1 C(j)=6*((y(i+1)-y(i))/h(i) - (y(i) - y(i - 1)) / h(i - 1)) End do ! Max tdma length ntdma = norder - 2 !Upper Triangularization Do i = 2 , ntdma R = B(i) / D(i - 1) D(i) = D(i) - R * A(i - 1) C(i) = C(i) - R * C(i - 1) End do ! Directly set the last C C(ntdma) = C(ntdma)/D(ntdma) ! Back Substitute Do i = (ntdma - 1) , 1, -1 C(i) = (C(i) - A(i) * C(i + 1)) / D(i) End do ! Switch from C to S Do i = 2 , (norder - 1) j = i - 1 ! Shift from TDMA coordinate system S(i) = C(j) End do S(1) = 0.0 S(norder) = 0.0 ! Calculate cubic ai,bi,ci and di from S and h Do i = 1 , (norder - 1) A(i) = (S(i + 1) - S(i)) / (6 * h(i)) B(i) = S(i) / 2. C(i) = (y(i + 1)-y(i))/h(i)-(2 * h(i) * S(i) + h(i) * S(i + 1))/6. D(i) = y(i) End do Do i = 1 , norder End do
  • 27. Plotting ! Read in steps nstep = 100 step = 0 Do i = 1 , (norder - 1) !'Discrete function Do j = 1 , nstep step = step + 1 xs = x(i) + (h(i) / nstep) * (j - 1) ys=A(i)*(xs - x(i))**3 + B(i)*(xs - x(i))**2 + C(i)*(xs - x(i)) + D(i) xr(step) = xs yr(step) = ys End do End do do i=1,step !print*,i,xr(i),yr(i) write(1,*)xr(i),yr(i) enddo End • fit is good except b/n x=3 & 4 w/c is caused by natural spline boundary conditions at x=0 & 4. • Changing the spline to reflect the correct 2nd derivative at x=4 would help the fit.