SlideShare a Scribd company logo
1 of 18
Chapter 06
& 07
LEAST SQUARES
FITTING OF CURVES
TO DATA
INTERPOLATION
4/5/2016 DR. MOHAMMED DANISH 1
Curve fitting
Curve fitting is also called regression analysis, is a process
of fitting a function to a set of data points.
The function can be used as a mathematical model of the
data.
There are many types of functions linear, polynomial,
power, exponential, etc, the curve fitting can be a
complicated process.
4/5/2016 DR. MOHAMMED DANISH 2
Least square curve fitting
The best line has minimum error between line and data
points:
This is called the least squares approach, when the square
of the error is minimum.
To find the minimum error, the derivative of the error with
respect to each a and b must be zero.
y ax b 
2
1
[ ( )]
N
i i
i
Error y ax b

  
4/5/2016 DR. MOHAMMED DANISH 3
2
1
1
2 2
1 1 1 1 1 1
2
1
[ ( )]
( )
0
( )
2 [ ( )] 0
0
[ ( )]
( )
0
( )
2 [ ( )] 0
N
i i
i
N
i i i
i
N N N N N N
i i i i i i i i
i i i i i i
N
i i
i
i i
y ax b
Error
a a
Error
x y ax b
a
x y a x b x x y a x b x
y ax b
Error
b b
Error
y ax b
b


     

 
      
 

    

     
 
      
 

    



     

1 1 1
,
N N N
i i
i i i
y a x bN
  
    
4/5/2016 DR. MOHAMMED DANISH 4
2
1 1 1
1 1
N N N
i i i i
i i i
N N
i i
i i
a x b x x y
a x bN y
  
 
 
 
  
 
1 1
2
1 1 1
N N
i i
i i
N N N
i i i i
i i i
matrix form
N x y
b
a
x x x y
 
  
   
    
    
    
   
   
 
  
4/5/2016 DR. MOHAMMED DANISH 5
1 1 1
2
2
1 1
2
1 1 1 1
2
2
1 1
N N N
i i i i
i i i
N N
i i
i i
N N N N
i i i i i
i i i i
N N
i i
i i
N x y x y
a
N x x
y x x x y
b
N x x
  
 
   
 


 
  
 


 
  
 
  
 
   
 
Linear least square fitting is a method to determine the best
coefficients in a linear model for given set of data.
4/5/2016 DR. MOHAMMED DANISH 6
Example 1
V
(m/s)
F
(N)
i xi yi (xi)2 xiyi
1 10 25 100 250
2 20 70 400 1400
3 30 380 900 11400
4 40 550 1600 22000
5 50 610 2500 30500
6 60 122
0
3600 73200
7 70 830 4900 58100
8 80 145
0
6400 116000
Σ 360 513
5
20400 312850
 
    
   
2 22
2
2 22
1
8 312850 360 5135
19.47024
8 20400 360
5135(20400) 360(312850)
8(20400) (360)
104754000 112626000 7872000
234.285
163200 129600 33600
641.
i i i i
i i
i i i i i
i i
N x y x y
a
N x x
y x x x y
b
N x x
b y a x
 
  

 
 
  
 
   

  
  
 
   
 
 875 19.47024 45 234.2857  
4/5/2016 DR. MOHAMMED DANISH 7
MATLAB function for least
square fitting of data
MATLAB programming has a built-in function polyfit
that fits a least squares nth order polynomial to data:
>>p=polyfit(x, y, n)
X: independent data
Y: dependent data
n: order of the polynomial to fit
p: coefficients of polynomial
1
1 2 1( ) ............n n
n nf x p X p X p X p
    
4/5/2016 DR. MOHAMMED DANISH 8
MATLAB function for least
square fitting of data
MATLAB’s polyval command can be used to compute a
value using the coefficients.
>>y=polyval(p, x)
4/5/2016 DR. MOHAMMED DANISH 9
Example 2
No x y
1 0.9 0.9
2 1.5 1.5
3 3 2.5
4 4 5.1
5 6 4.5
6 8 4.9
7 9.5 6.3
Write the MATLAB programing for the 3rd order curve fitting
For the given data.
Solution:
%create vectors x and y with the coordinates of
the data points.
>>x=[0.9 1.5 3 4 6 8 9.5]
>>y=[0.9 1.5 2.5 5.1 4.5 4.9 6.3]
%create a vector p using polyfit command
>>p=polyfit(x,y,3)
For plot, >>xp=0.9:0.1:9.5;
>>yp=polyval(p,xp)
>>plot(x,y, ‘o’, xp,yp)
>>xlabel(‘x’); ylabel(‘y’)
4/5/2016 DR. MOHAMMED DANISH 10
07: Interpolation
Interpolation is the estimation of values between the data points.
You will frequently have occasions to estimate intermediate values
between precise data points.
The function you use to interpolate must pass through the actual data
points - this makes interpolation more restrictive than fitting.
In one dimensional interpolation each point has one independent
variable (say x) and one dependent variable (say y).
In two dimensional interpolation each point has two independent
variable (say x and y) and one depend variable (say z).
4/5/2016 DR. MOHAMMED DANISH 11
One dimensional interpolation
If only two data points are available, the points can be connected with
a straight line, and linear equation (polynomial of first order) can be
used to estimate the values between the data points.
A more accurate interpolation can be obtained if instead of
considering all the points in the data set(by using one polynomial that
passes through all the points), only a few data points in the
neighborhood where the interpolation is needed is considered. This
method is called spline interpolation, where many low order
polynomials are used, each is valid only in a small domain of the data
set.
The simplest method of spline interpolation is called linear spline
interpolation
4/5/2016 DR. MOHAMMED DANISH 12
One dimensional interpolation
In spline interpolation method every two adjacent points are connected
with a straight line (a polynomial of first degree).
The equation of straight line that passes through two adjacent points
(xi,yi)and (xi+1,yi+1) and that can be used to calculate the value of y for any x
between the points
In linear interpolation the line between two data points has a constant
slope, and there is change in the slope at every point.
A smoother interpolation curve can be obtained by using quadratic or
cubic polynomials. In these methods, called quadratic splines and cubic
splines, a second order or third order polynomial used to interpolate
between every two points.
1 1 1
1 1
i i i i i i
i i i i
y y y x y x
y x
x x x x
  
 
 
 
 
4/5/2016 DR. MOHAMMED DANISH 13
MATLAB command for
Interpolation
One dimensional interpolation in MATLAB is done with the interp1
function, which has the form:
Yi=interp1(x,y,xi, ‘method’)
Yi=interpolated value
The x & y is the horizontal and vertical co-
ordinates of input data.
The xi is the horizontal coordinate of the
interpolation point independent variable
‘method’ method of interpolation such as
‘nearest’ ‘linear’ ‘spline’ ‘pchip’
4/5/2016 DR. MOHAMMED DANISH 14
MATLAB command for
Interpolation
Nearest- return the value of the
data point that is nearest to the
interpolated point.
Linear- uses linear spline
interpolation.
Spline- uses cubic spline
interpolation.
Pchip-uses piecewise cubic
hermite interpolation, also called
cubic
When ‘nearest’ and ‘linear’
methods are used , the values of xi
must be within the domain of x.
If the ‘spline’ or ‘pchip’ methods
are used, xi can have values
outside the domain of x and the
function interp1 perform
extrapolation.
If no method is specified, the
default is ‘linear’.
4/5/2016 DR. MOHAMMED DANISH 15
Computing the interpolating
polynomial in MATLAB
Suppose, x= 1.1, 1.2, 1.3
f(x)=0.8912, 0.9320, 0.9636
Interms of MATLAB command,
>>x=[1.1; 1.2; 1.3]
>>y=[0.8912; 0.9320;
0.9636]
>>v=vander(x)
1.2100 1.1000 1.0000
1.4400 1.2000 1.0000
1.6900 1.3000 1.0000
>>a=vf
-0.4600
1.46660
-0.1648
>>polyval(a, 1.15)
Ans=
0.91275
4/5/2016 DR. MOHAMMED DANISH 16
Example 3
For function, following data were given. Use linear, spline,
and pchip interpolation methods to calculate the value of y between the
points.
the following program written in the script file that solve
the problem:
>>x=0:1:5
>>y=[1.0 -0.6242 -1.4707 3.2406 -0.7366 -
6.3717]
>>xi=0:0.1:5;
>>yilin=interp1(x,y,xi, ‘linear’)
>>yispl=interp1(x,y,xi, ‘spline’)
( ) 1.5 cos(2 )x
f x x
No x y
1 0 1.0
2 1 -0.6242
3 2 -1.4707
4 3 3.2406
5 4 -0.7366
6 5 -6.3717
4/5/2016 DR. MOHAMMED DANISH 17
Slide ends here
Dr. Mohammed Danish
Sr. Lecturer, Malaysian Institute of Chemical and
bioengineering Technology (MICET), UniKL, Alor
Gajah 78000 Melaka, Malaysia
4/5/2016 DR. MOHAMMED DANISH 18

More Related Content

What's hot

Real time implementation of unscented kalman filter for target tracking
Real time implementation of unscented kalman filter for target trackingReal time implementation of unscented kalman filter for target tracking
Real time implementation of unscented kalman filter for target tracking
IAEME Publication
 

What's hot (20)

Spline interpolation numerical methods presentation
Spline interpolation numerical methods presentationSpline interpolation numerical methods presentation
Spline interpolation numerical methods presentation
 
Convex Optimization
Convex OptimizationConvex Optimization
Convex Optimization
 
Newton raphson method
Newton raphson methodNewton raphson method
Newton raphson method
 
Numerical Analysis (Solution of Non-Linear Equations) part 2
Numerical Analysis (Solution of Non-Linear Equations) part 2Numerical Analysis (Solution of Non-Linear Equations) part 2
Numerical Analysis (Solution of Non-Linear Equations) part 2
 
Fixed point iteration
Fixed point iterationFixed point iteration
Fixed point iteration
 
Secant Method
Secant MethodSecant Method
Secant Method
 
Kalman filters
Kalman filtersKalman filters
Kalman filters
 
Newton's forward & backward interpolation
Newton's forward & backward interpolationNewton's forward & backward interpolation
Newton's forward & backward interpolation
 
Es272 ch3a
Es272 ch3aEs272 ch3a
Es272 ch3a
 
Bisection method
Bisection methodBisection method
Bisection method
 
Interpolation with Finite differences
Interpolation with Finite differencesInterpolation with Finite differences
Interpolation with Finite differences
 
decision tree regression
decision tree regressiondecision tree regression
decision tree regression
 
Kalman filters
Kalman filtersKalman filters
Kalman filters
 
Real time implementation of unscented kalman filter for target tracking
Real time implementation of unscented kalman filter for target trackingReal time implementation of unscented kalman filter for target tracking
Real time implementation of unscented kalman filter for target tracking
 
Newton's Forward/Backward Difference Interpolation
Newton's Forward/Backward  Difference InterpolationNewton's Forward/Backward  Difference Interpolation
Newton's Forward/Backward Difference Interpolation
 
Gaussian quadratures
Gaussian quadraturesGaussian quadratures
Gaussian quadratures
 
Introduction to Approximation Algorithms
Introduction to Approximation AlgorithmsIntroduction to Approximation Algorithms
Introduction to Approximation Algorithms
 
Aitken’s method
Aitken’s methodAitken’s method
Aitken’s method
 
Interpolation and its applications
Interpolation and its applicationsInterpolation and its applications
Interpolation and its applications
 
Secant method
Secant methodSecant method
Secant method
 

Similar to 06-07 Chapter interpolation in MATLAB

Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)
IJERD Editor
 
Ijarcet vol-2-issue-4-1579-1582
Ijarcet vol-2-issue-4-1579-1582Ijarcet vol-2-issue-4-1579-1582
Ijarcet vol-2-issue-4-1579-1582
Editor IJARCET
 
Statistical software for Sampling from Finite Populations: an analysis using ...
Statistical software for Sampling from Finite Populations: an analysis using ...Statistical software for Sampling from Finite Populations: an analysis using ...
Statistical software for Sampling from Finite Populations: an analysis using ...
michele de meo
 
B02110105012
B02110105012B02110105012
B02110105012
theijes
 
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
ijceronline
 
Vol 9 No 1 - January 2014
Vol 9 No 1 - January 2014Vol 9 No 1 - January 2014
Vol 9 No 1 - January 2014
ijcsbi
 
Classification of handwritten characters by their symmetry features
Classification of handwritten characters by their symmetry featuresClassification of handwritten characters by their symmetry features
Classification of handwritten characters by their symmetry features
AYUSH RAJ
 
2014-mo444-practical-assignment-04-paulo_faria
2014-mo444-practical-assignment-04-paulo_faria2014-mo444-practical-assignment-04-paulo_faria
2014-mo444-practical-assignment-04-paulo_faria
Paulo Faria
 
MolinaLeydi_FinalProject
MolinaLeydi_FinalProjectMolinaLeydi_FinalProject
MolinaLeydi_FinalProject
Leydi Molina
 
Singh presentation
Singh presentationSingh presentation
Singh presentation
gagan22
 

Similar to 06-07 Chapter interpolation in MATLAB (20)

Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)
 
Ijarcet vol-2-issue-4-1579-1582
Ijarcet vol-2-issue-4-1579-1582Ijarcet vol-2-issue-4-1579-1582
Ijarcet vol-2-issue-4-1579-1582
 
A Derivative Free High Ordered Hybrid Equation Solver
A Derivative Free High Ordered Hybrid Equation Solver  A Derivative Free High Ordered Hybrid Equation Solver
A Derivative Free High Ordered Hybrid Equation Solver
 
Statistical software for Sampling from Finite Populations: an analysis using ...
Statistical software for Sampling from Finite Populations: an analysis using ...Statistical software for Sampling from Finite Populations: an analysis using ...
Statistical software for Sampling from Finite Populations: an analysis using ...
 
A DERIVATIVE FREE HIGH ORDERED HYBRID EQUATION SOLVER
A DERIVATIVE FREE HIGH ORDERED HYBRID EQUATION SOLVERA DERIVATIVE FREE HIGH ORDERED HYBRID EQUATION SOLVER
A DERIVATIVE FREE HIGH ORDERED HYBRID EQUATION SOLVER
 
B02110105012
B02110105012B02110105012
B02110105012
 
The International Journal of Engineering and Science (The IJES)
 The International Journal of Engineering and Science (The IJES) The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)
 
Lecture7 xing fei-fei
Lecture7 xing fei-feiLecture7 xing fei-fei
Lecture7 xing fei-fei
 
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
 
Vol 9 No 1 - January 2014
Vol 9 No 1 - January 2014Vol 9 No 1 - January 2014
Vol 9 No 1 - January 2014
 
D026017036
D026017036D026017036
D026017036
 
Classification of handwritten characters by their symmetry features
Classification of handwritten characters by their symmetry featuresClassification of handwritten characters by their symmetry features
Classification of handwritten characters by their symmetry features
 
2014-mo444-practical-assignment-04-paulo_faria
2014-mo444-practical-assignment-04-paulo_faria2014-mo444-practical-assignment-04-paulo_faria
2014-mo444-practical-assignment-04-paulo_faria
 
MolinaLeydi_FinalProject
MolinaLeydi_FinalProjectMolinaLeydi_FinalProject
MolinaLeydi_FinalProject
 
Introduction to simulating data to improve your research
Introduction to simulating data to improve your researchIntroduction to simulating data to improve your research
Introduction to simulating data to improve your research
 
A derivative free high ordered hybrid equation solver
A derivative free high ordered hybrid equation solverA derivative free high ordered hybrid equation solver
A derivative free high ordered hybrid equation solver
 
Data fitting in Scilab - Tutorial
Data fitting in Scilab - TutorialData fitting in Scilab - Tutorial
Data fitting in Scilab - Tutorial
 
A Robust Method Based On LOVO Functions For Solving Least Squares Problems
A Robust Method Based On LOVO Functions For Solving Least Squares ProblemsA Robust Method Based On LOVO Functions For Solving Least Squares Problems
A Robust Method Based On LOVO Functions For Solving Least Squares Problems
 
Singh presentation
Singh presentationSingh presentation
Singh presentation
 
Computation Using Scipy, Scikit Image, Scikit Learn
Computation Using Scipy, Scikit Image, Scikit LearnComputation Using Scipy, Scikit Image, Scikit Learn
Computation Using Scipy, Scikit Image, Scikit Learn
 

More from Dr. Mohammed Danish

More from Dr. Mohammed Danish (17)

Instrumental method of analysis Oil and Fat(Unit 7 b)
Instrumental method of analysis Oil and Fat(Unit 7 b)Instrumental method of analysis Oil and Fat(Unit 7 b)
Instrumental method of analysis Oil and Fat(Unit 7 b)
 
Analysis of oil and Fat(Unit 7)
Analysis of oil and Fat(Unit 7)Analysis of oil and Fat(Unit 7)
Analysis of oil and Fat(Unit 7)
 
Non edible application of oil and Fat (Unit 6 b)
Non edible application of oil and Fat (Unit 6 b)Non edible application of oil and Fat (Unit 6 b)
Non edible application of oil and Fat (Unit 6 b)
 
Oil and Fat edible applications (Unit 6 a)
Oil and Fat edible applications (Unit 6 a)Oil and Fat edible applications (Unit 6 a)
Oil and Fat edible applications (Unit 6 a)
 
Fatty acid reaction and derivatives (Unit 5 b)
 Fatty acid reaction and derivatives (Unit 5 b) Fatty acid reaction and derivatives (Unit 5 b)
Fatty acid reaction and derivatives (Unit 5 b)
 
Fatty acid clusters (Unit 5 a)
Fatty acid clusters (Unit 5 a) Fatty acid clusters (Unit 5 a)
Fatty acid clusters (Unit 5 a)
 
Production of Glycerin (Unit 4 b)
Production of Glycerin (Unit 4 b) Production of Glycerin (Unit 4 b)
Production of Glycerin (Unit 4 b)
 
Fatty Acid Isolation (Unit 4 a)
Fatty Acid Isolation (Unit 4 a)Fatty Acid Isolation (Unit 4 a)
Fatty Acid Isolation (Unit 4 a)
 
Processing of edible oil (Unit 3)
Processing of edible oil (Unit 3)Processing of edible oil (Unit 3)
Processing of edible oil (Unit 3)
 
Chemical and Physical properties of Oil and Fat (Unit 2)
Chemical and Physical properties of Oil and Fat (Unit 2)Chemical and Physical properties of Oil and Fat (Unit 2)
Chemical and Physical properties of Oil and Fat (Unit 2)
 
Introduction of Edible oils (Unit 1)
Introduction of Edible oils (Unit 1) Introduction of Edible oils (Unit 1)
Introduction of Edible oils (Unit 1)
 
01 Chapter MATLAB introduction
01 Chapter MATLAB introduction01 Chapter MATLAB introduction
01 Chapter MATLAB introduction
 
08-09 Chapter numerical integration
08-09  Chapter numerical integration 08-09  Chapter numerical integration
08-09 Chapter numerical integration
 
05 Chapter MATLAB Differntial equations
05 Chapter MATLAB Differntial equations05 Chapter MATLAB Differntial equations
05 Chapter MATLAB Differntial equations
 
04 Chapter MATLAB linear algebra review
04 Chapter MATLAB linear algebra review04 Chapter MATLAB linear algebra review
04 Chapter MATLAB linear algebra review
 
03 Chapter MATLAB finite precision arithmatic
03 Chapter MATLAB finite precision arithmatic03 Chapter MATLAB finite precision arithmatic
03 Chapter MATLAB finite precision arithmatic
 
02 MATLAB programming
02 MATLAB programming02 MATLAB programming
02 MATLAB programming
 

Recently uploaded

Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
HyderabadDolls
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Klinik kandungan
 
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
HyderabadDolls
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...
Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...
Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...
HyderabadDolls
 
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
nirzagarg
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
HyderabadDolls
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
gajnagarg
 

Recently uploaded (20)

Digital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareDigital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham Ware
 
Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?
 
Predictive Precipitation: Advanced Rain Forecasting Techniques
Predictive Precipitation: Advanced Rain Forecasting TechniquesPredictive Precipitation: Advanced Rain Forecasting Techniques
Predictive Precipitation: Advanced Rain Forecasting Techniques
 
👉 Bhilai Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl Ser...
👉 Bhilai Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl Ser...👉 Bhilai Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl Ser...
👉 Bhilai Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl Ser...
 
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
 
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
 
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
 
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...
Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...
Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...
 
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for Research
 
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubai
 
Giridih Escorts Service Girl ^ 9332606886, WhatsApp Anytime Giridih
Giridih Escorts Service Girl ^ 9332606886, WhatsApp Anytime GiridihGiridih Escorts Service Girl ^ 9332606886, WhatsApp Anytime Giridih
Giridih Escorts Service Girl ^ 9332606886, WhatsApp Anytime Giridih
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
 

06-07 Chapter interpolation in MATLAB

  • 1. Chapter 06 & 07 LEAST SQUARES FITTING OF CURVES TO DATA INTERPOLATION 4/5/2016 DR. MOHAMMED DANISH 1
  • 2. Curve fitting Curve fitting is also called regression analysis, is a process of fitting a function to a set of data points. The function can be used as a mathematical model of the data. There are many types of functions linear, polynomial, power, exponential, etc, the curve fitting can be a complicated process. 4/5/2016 DR. MOHAMMED DANISH 2
  • 3. Least square curve fitting The best line has minimum error between line and data points: This is called the least squares approach, when the square of the error is minimum. To find the minimum error, the derivative of the error with respect to each a and b must be zero. y ax b  2 1 [ ( )] N i i i Error y ax b     4/5/2016 DR. MOHAMMED DANISH 3
  • 4. 2 1 1 2 2 1 1 1 1 1 1 2 1 [ ( )] ( ) 0 ( ) 2 [ ( )] 0 0 [ ( )] ( ) 0 ( ) 2 [ ( )] 0 N i i i N i i i i N N N N N N i i i i i i i i i i i i i i N i i i i i y ax b Error a a Error x y ax b a x y a x b x x y a x b x y ax b Error b b Error y ax b b                                                             1 1 1 , N N N i i i i i y a x bN         4/5/2016 DR. MOHAMMED DANISH 4
  • 5. 2 1 1 1 1 1 N N N i i i i i i i N N i i i i a x b x x y a x bN y               1 1 2 1 1 1 N N i i i i N N N i i i i i i i matrix form N x y b a x x x y                                      4/5/2016 DR. MOHAMMED DANISH 5
  • 6. 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 1 N N N i i i i i i i N N i i i i N N N N i i i i i i i i i N N i i i i N x y x y a N x x y x x x y b N x x                                         Linear least square fitting is a method to determine the best coefficients in a linear model for given set of data. 4/5/2016 DR. MOHAMMED DANISH 6
  • 7. Example 1 V (m/s) F (N) i xi yi (xi)2 xiyi 1 10 25 100 250 2 20 70 400 1400 3 30 380 900 11400 4 40 550 1600 22000 5 50 610 2500 30500 6 60 122 0 3600 73200 7 70 830 4900 58100 8 80 145 0 6400 116000 Σ 360 513 5 20400 312850            2 22 2 2 22 1 8 312850 360 5135 19.47024 8 20400 360 5135(20400) 360(312850) 8(20400) (360) 104754000 112626000 7872000 234.285 163200 129600 33600 641. i i i i i i i i i i i i i N x y x y a N x x y x x x y b N x x b y a x                                    875 19.47024 45 234.2857   4/5/2016 DR. MOHAMMED DANISH 7
  • 8. MATLAB function for least square fitting of data MATLAB programming has a built-in function polyfit that fits a least squares nth order polynomial to data: >>p=polyfit(x, y, n) X: independent data Y: dependent data n: order of the polynomial to fit p: coefficients of polynomial 1 1 2 1( ) ............n n n nf x p X p X p X p      4/5/2016 DR. MOHAMMED DANISH 8
  • 9. MATLAB function for least square fitting of data MATLAB’s polyval command can be used to compute a value using the coefficients. >>y=polyval(p, x) 4/5/2016 DR. MOHAMMED DANISH 9
  • 10. Example 2 No x y 1 0.9 0.9 2 1.5 1.5 3 3 2.5 4 4 5.1 5 6 4.5 6 8 4.9 7 9.5 6.3 Write the MATLAB programing for the 3rd order curve fitting For the given data. Solution: %create vectors x and y with the coordinates of the data points. >>x=[0.9 1.5 3 4 6 8 9.5] >>y=[0.9 1.5 2.5 5.1 4.5 4.9 6.3] %create a vector p using polyfit command >>p=polyfit(x,y,3) For plot, >>xp=0.9:0.1:9.5; >>yp=polyval(p,xp) >>plot(x,y, ‘o’, xp,yp) >>xlabel(‘x’); ylabel(‘y’) 4/5/2016 DR. MOHAMMED DANISH 10
  • 11. 07: Interpolation Interpolation is the estimation of values between the data points. You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate must pass through the actual data points - this makes interpolation more restrictive than fitting. In one dimensional interpolation each point has one independent variable (say x) and one dependent variable (say y). In two dimensional interpolation each point has two independent variable (say x and y) and one depend variable (say z). 4/5/2016 DR. MOHAMMED DANISH 11
  • 12. One dimensional interpolation If only two data points are available, the points can be connected with a straight line, and linear equation (polynomial of first order) can be used to estimate the values between the data points. A more accurate interpolation can be obtained if instead of considering all the points in the data set(by using one polynomial that passes through all the points), only a few data points in the neighborhood where the interpolation is needed is considered. This method is called spline interpolation, where many low order polynomials are used, each is valid only in a small domain of the data set. The simplest method of spline interpolation is called linear spline interpolation 4/5/2016 DR. MOHAMMED DANISH 12
  • 13. One dimensional interpolation In spline interpolation method every two adjacent points are connected with a straight line (a polynomial of first degree). The equation of straight line that passes through two adjacent points (xi,yi)and (xi+1,yi+1) and that can be used to calculate the value of y for any x between the points In linear interpolation the line between two data points has a constant slope, and there is change in the slope at every point. A smoother interpolation curve can be obtained by using quadratic or cubic polynomials. In these methods, called quadratic splines and cubic splines, a second order or third order polynomial used to interpolate between every two points. 1 1 1 1 1 i i i i i i i i i i y y y x y x y x x x x x            4/5/2016 DR. MOHAMMED DANISH 13
  • 14. MATLAB command for Interpolation One dimensional interpolation in MATLAB is done with the interp1 function, which has the form: Yi=interp1(x,y,xi, ‘method’) Yi=interpolated value The x & y is the horizontal and vertical co- ordinates of input data. The xi is the horizontal coordinate of the interpolation point independent variable ‘method’ method of interpolation such as ‘nearest’ ‘linear’ ‘spline’ ‘pchip’ 4/5/2016 DR. MOHAMMED DANISH 14
  • 15. MATLAB command for Interpolation Nearest- return the value of the data point that is nearest to the interpolated point. Linear- uses linear spline interpolation. Spline- uses cubic spline interpolation. Pchip-uses piecewise cubic hermite interpolation, also called cubic When ‘nearest’ and ‘linear’ methods are used , the values of xi must be within the domain of x. If the ‘spline’ or ‘pchip’ methods are used, xi can have values outside the domain of x and the function interp1 perform extrapolation. If no method is specified, the default is ‘linear’. 4/5/2016 DR. MOHAMMED DANISH 15
  • 16. Computing the interpolating polynomial in MATLAB Suppose, x= 1.1, 1.2, 1.3 f(x)=0.8912, 0.9320, 0.9636 Interms of MATLAB command, >>x=[1.1; 1.2; 1.3] >>y=[0.8912; 0.9320; 0.9636] >>v=vander(x) 1.2100 1.1000 1.0000 1.4400 1.2000 1.0000 1.6900 1.3000 1.0000 >>a=vf -0.4600 1.46660 -0.1648 >>polyval(a, 1.15) Ans= 0.91275 4/5/2016 DR. MOHAMMED DANISH 16
  • 17. Example 3 For function, following data were given. Use linear, spline, and pchip interpolation methods to calculate the value of y between the points. the following program written in the script file that solve the problem: >>x=0:1:5 >>y=[1.0 -0.6242 -1.4707 3.2406 -0.7366 - 6.3717] >>xi=0:0.1:5; >>yilin=interp1(x,y,xi, ‘linear’) >>yispl=interp1(x,y,xi, ‘spline’) ( ) 1.5 cos(2 )x f x x No x y 1 0 1.0 2 1 -0.6242 3 2 -1.4707 4 3 3.2406 5 4 -0.7366 6 5 -6.3717 4/5/2016 DR. MOHAMMED DANISH 17
  • 18. Slide ends here Dr. Mohammed Danish Sr. Lecturer, Malaysian Institute of Chemical and bioengineering Technology (MICET), UniKL, Alor Gajah 78000 Melaka, Malaysia 4/5/2016 DR. MOHAMMED DANISH 18