Professional Documents
Culture Documents
Curve Fitting Least Square Fit Method: Sandeep Kumar
Curve Fitting Least Square Fit Method: Sandeep Kumar
Curve Fitting Least Square Fit Method: Sandeep Kumar
Curve fitting examines the relationship between one or more independent variables and dependent
variables with the goal of defining the ‘best fit’ model.
WE WILL USE
LEAST SQUARE METHOD
TO FIT THE CURVE
LEAST SQAURE METHOD
Error: y
at x = x1; e1 = y 1
– f(x1)
e4 f(x)
at x = x2; e2 = y 2 e3
e5
– f(x2)
at x = x3; e3 = y 3 e2
e1
–.f(x3) .
. .
at x = xi; ei = yi – f(xi) x
𝑛
𝐸 =∑ ( 𝑦 𝑖 − 𝑓 ( 𝑥 𝑖 ) )
2
𝑖=1
𝑛
𝐸=∑ ( 𝑦 𝑖 − ( 𝑏 𝑥𝑖 + 𝑎 ) )
2
𝑖=1
𝛿𝐸 𝛿𝐸
=0 and =0
𝛿𝑎 𝛿𝑏
𝑛 𝛿𝐸
=0
𝐸=∑ 𝑒 𝑖2 𝛿𝑎
( )
𝑖=1 𝑛
𝛿𝐸 𝛿
∑ [ 𝑦 𝑖 − ( 𝑏 𝑥 𝑖 − 𝑎) ] =0
2
𝑛 =
𝐸 =∑ ( 𝑦 𝑖 − 𝑓 ( 𝑥 𝑖 ) ) 𝛿 𝑎 𝛿𝑎
2
𝑖
∑ 𝑦𝑖=𝑛𝑎+𝑏 ∑ 𝑥𝑖
𝑖=1
𝑛 (A)
𝐸=∑ ( 𝑦 𝑖 − ( 𝑏 𝑥𝑖 + 𝑎 ) )
2
𝑖=1
(∑ [ )
𝑛
𝛿𝐸 𝛿𝐸 𝛿𝐸 𝛿 2
𝛿𝑎
=0 and
𝛿𝑏
=0 = 𝑦 𝑖 − ( 𝑏 𝑥 𝑖 − 𝑎 ) ] =0
𝛿𝑏 𝛿𝑏 𝑖
∑ 𝑥𝑖 𝑦𝑖=𝑎 ∑ 𝑥𝑖+𝑏∑ 𝑥𝑖 2
(B)
On solving the two equation (A) and (B), we get:
( ∑ 𝑦 ∑ 𝑥 2 ) − ( ∑ 𝑥 ∑ 𝑥𝑦 )
𝑎= 2
𝑛∑ 𝑥 − ( ∑ 𝑥 )
2
( ∑ 𝑥 ∑ 𝑦 ) − ( 𝑛 ∑ 𝑥𝑦 )
𝑏= 2
( ∑ 𝑥 ) − 𝑛 ∑ 𝑥2
SIMPLE EFFICIENT
COMPLIER
Presently
we are using fortran 95 which has
many new features as compared to Fortran
77.
FLOWCHART
PRINT a and b
DO i = 1 to n
END
NEXT i
ALGORITHM
1. Start the program.
6. In the same loop we update the sums as:
2. Use implicit none to diable the already
declared variables. sumx = sumx + x(i)
print*, "Enter the number of points" !Insert the number of data of the experiment
read*, n
do i=1, n
read(1, *)x,y !Inserts input from a pre-existing file
sx=sx+x
sy=sy+y
sxy=sxy+(x*y)
sx2=sx2+(x**2)
enddo
a=((sy*sx2)-(sx*sxy))/((n*sx2)-(sx**2)) !Calculates the intercept
b=((n*sxy)-(sx*sy))/((n*sx2)-(sx**2)) !Calculates the slope
print*,'y=',b,'x+(',a,')’ !Prints the required result
end program curve
DATA FILE
Curvedata1.dat
0.5,0.31
1,0.82
1.5,1.29
2,1.85
2.5,2.51
3,3.02
OUTPUT
Need of curve fitting??
TESTING EXISTING MATHEMATICAL RELATION
ESTABLISHING NEW ONES
PREDICTING UNKNOWN VALUES
IN PHYSICS
THANK YOU