SlideShare a Scribd company logo
1 of 11
PRACTICAL
Name- Saloni Singhal
M.Sc. (Statistics) II-Sem.
Roll No: 2046398
Course- MATH-409 L
Numerical Analysis Lab
Submitted To: Dr. S.C. Pandey
OBJECTIVE
1. Create an M-file to implement
Newton Gregory Forward Interpolation.
1. Curve Fitting- Least Square nth order
polynomial to data.
Theory
Then the process of knowing the value of f(x ) for some unknown
value of x not explicitly given in the interval [a, b] is called
interpolation. The value thus, determined is known as Interpolated
value.
This Newton Gregory Forward Interpolation formula is particularly
useful for interpolating the values of f(x) near the beginning of the
set of values given. h is called the interval of difference and u = (
x – a ) / h, Here a is the first term.
Error term of the formula:
Program
clear;
%input number of data points
n= input('enter number of data points=');
%input abscissa and ordinate value
for a=1:n
X(a)= input('enter X'+string(a));
end
for b=1:n
Y(b)= input('enter Y'+string(b));
end %enter the value to be interpolated using
forward interpolation
x=input('enter value of x to be interpolated');
%step size h and d gives the forward difference
table
h=X(2)-X(1);
for i=1:n-1
d(i,1)=Y(i+1)-Y(i);
end
for j=2:n-1
for i=1:n-j
d(i,j)=d(i+1,j-1)-d(i,j-1);
end
end
Program Contd.
P1=linspace(min(X),max(X),51);
P2=zeros(51,1);
for i=1:51
P2(i)=nf(P1(i),X,Y,n,d);
end
%plot for the given points
plot(X,Y)
hold on
%plot for the interpoated curve
plot(P1,P2)
hold off
d
nf(x,X,Y,n,d)
% function to calculate the forward inoterpolation
function y=nf(u,X,Y,n,d)
h=X(2)-X(1);
p=(u-X(1))/h;
prod=1;
y=Y(1);
for t=1:n-1
prod=prod*(p-t+1)/t;
y=y+prod*d(1,t);
end
end
Time Complexity
6
For the given program it is calculated as:
For line 14= 2(n-1) since loop
For line 16= (n-1)+1 since loop from 1:n-1
For line 18= 2(n-1)(n-2) for nested loop
For line 24= 51(6n-3) since linspace generates 51
values(given) and min/max has time complexity n
For line 36= (6n-3) since loop is from i to n-1
on adding the above dominant value is =O(n2)
Big O notation is the most common metric for calculating time complexity. It
describes the execution time of a task in relation to the number of steps
required to complete it.
We calculate the
no of operations in
respective loops
and function.
Big ‘O’ notation
takes its dominant
value
Output
Plot of the given data points and interpolated curve
Reference:
— Data Points
plot
—Interpolated
curve
Curve Fitting
Syntax:
p = polyfit(x,y,n)
returns the coefficients
for a polynomial p(x) of
degree n that is a best
fit (in a least-squares
sense) for the data in y.
The coefficients in p are
in descending powers,
and the length of p is
n+1
Conclusion
• The interpolated value of the point is as shown
in figure.
• Polyfit (order 3) verifies the actual cubic
formula for the given set of data points i.e. y=
x³+2x-3.
Caveats
It can be observed that this formula is appropriate when
the value to be interpolated (xs) lie almost in the beginning
of the data table. More explicitly, when xs lies almost in the
end of the data table then only first two or three terms of
(1) can be taken into consideration to keep | s | < 1.
and hence the result will not be sufficiently accurate.
To overcome this problem, we go for next formula named
Newton’s Backward difference formula.

More Related Content

Similar to Newton Forward Interpolation

01 EC 7311-Module IV.pptx
01 EC 7311-Module IV.pptx01 EC 7311-Module IV.pptx
01 EC 7311-Module IV.pptxVSUDHEER4
 
A New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmA New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmJim Jimenez
 
Introducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosIntroducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosluzenith_g
 
Newton cotes integration method
Newton cotes integration  methodNewton cotes integration  method
Newton cotes integration methodshashikant pabari
 
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptx
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptxASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptx
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptxsunitha1792
 
Matlab polynimials and curve fitting
Matlab polynimials and curve fittingMatlab polynimials and curve fitting
Matlab polynimials and curve fittingAmeen San
 
module1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdfmodule1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdfShiwani Gupta
 
Implementation of K-Nearest Neighbor Algorithm
Implementation of K-Nearest Neighbor AlgorithmImplementation of K-Nearest Neighbor Algorithm
Implementation of K-Nearest Neighbor AlgorithmDipesh Shome
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematicalbabuk110
 
Numerical Methods
Numerical MethodsNumerical Methods
Numerical MethodsTeja Ande
 
Ch-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsCh-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsMAHERMOHAMED27
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptxKokilaK25
 
Computational Complexity.pptx
Computational Complexity.pptxComputational Complexity.pptx
Computational Complexity.pptxEnosSalar
 
Fixed Point Interation
Fixed Point InterationFixed Point Interation
Fixed Point InterationSaloni Singhal
 
interpolation-and-its-application-180107160107.pptx
interpolation-and-its-application-180107160107.pptxinterpolation-and-its-application-180107160107.pptx
interpolation-and-its-application-180107160107.pptxSomitSamanto1
 
Perspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer SheetPerspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer SheetHoang Nguyen Phong
 

Similar to Newton Forward Interpolation (20)

01 EC 7311-Module IV.pptx
01 EC 7311-Module IV.pptx01 EC 7311-Module IV.pptx
01 EC 7311-Module IV.pptx
 
Alg1
Alg1Alg1
Alg1
 
A New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmA New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring Algorithm
 
Introducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosIntroducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmos
 
Newton cotes integration method
Newton cotes integration  methodNewton cotes integration  method
Newton cotes integration method
 
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptx
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptxASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptx
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptx
 
Matlab polynimials and curve fitting
Matlab polynimials and curve fittingMatlab polynimials and curve fitting
Matlab polynimials and curve fitting
 
module1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdfmodule1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdf
 
parallel
parallelparallel
parallel
 
algo_vc_lecture8.ppt
algo_vc_lecture8.pptalgo_vc_lecture8.ppt
algo_vc_lecture8.ppt
 
Implementation of K-Nearest Neighbor Algorithm
Implementation of K-Nearest Neighbor AlgorithmImplementation of K-Nearest Neighbor Algorithm
Implementation of K-Nearest Neighbor Algorithm
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 
Numerical Methods
Numerical MethodsNumerical Methods
Numerical Methods
 
Ch-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsCh-2 final exam documet compler design elements
Ch-2 final exam documet compler design elements
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Computational Complexity.pptx
Computational Complexity.pptxComputational Complexity.pptx
Computational Complexity.pptx
 
Fixed Point Interation
Fixed Point InterationFixed Point Interation
Fixed Point Interation
 
interpolation-and-its-application-180107160107.pptx
interpolation-and-its-application-180107160107.pptxinterpolation-and-its-application-180107160107.pptx
interpolation-and-its-application-180107160107.pptx
 
Perspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer SheetPerspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer Sheet
 

More from Saloni Singhal

More from Saloni Singhal (20)

Finite Difference Method
Finite Difference MethodFinite Difference Method
Finite Difference Method
 
Runge Kutta Method
Runge Kutta MethodRunge Kutta Method
Runge Kutta Method
 
Euler Method
Euler MethodEuler Method
Euler Method
 
Simpson's Three-Eighth Method
Simpson's Three-Eighth MethodSimpson's Three-Eighth Method
Simpson's Three-Eighth Method
 
Trapezoidal Rule
Trapezoidal RuleTrapezoidal Rule
Trapezoidal Rule
 
Simpson One-Third
Simpson One-ThirdSimpson One-Third
Simpson One-Third
 
Forward & Backward Differenece Table
Forward & Backward Differenece TableForward & Backward Differenece Table
Forward & Backward Differenece Table
 
Bisection Method
Bisection MethodBisection Method
Bisection Method
 
Newton's Raphson method
Newton's Raphson methodNewton's Raphson method
Newton's Raphson method
 
Power Method
Power MethodPower Method
Power Method
 
Eigen Show
Eigen ShowEigen Show
Eigen Show
 
Inverse Power Method
 Inverse Power Method Inverse Power Method
Inverse Power Method
 
Convergence Analysis
Convergence AnalysisConvergence Analysis
Convergence Analysis
 
MARLAB codes for Gauss Seidel
MARLAB codes for Gauss SeidelMARLAB codes for Gauss Seidel
MARLAB codes for Gauss Seidel
 
MATLAB Codes for Jacobi method
MATLAB Codes for Jacobi methodMATLAB Codes for Jacobi method
MATLAB Codes for Jacobi method
 
L-U Decomposition
L-U DecompositionL-U Decomposition
L-U Decomposition
 
Gauss Elimination (without pivot).pptx
Gauss Elimination (without pivot).pptxGauss Elimination (without pivot).pptx
Gauss Elimination (without pivot).pptx
 
Gauss Elimination (With Partial Pivot)
Gauss Elimination (With Partial Pivot)Gauss Elimination (With Partial Pivot)
Gauss Elimination (With Partial Pivot)
 
Error analysis
Error analysisError analysis
Error analysis
 
Flow of control
Flow of controlFlow of control
Flow of control
 

Recently uploaded

Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...amitlee9823
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...amitlee9823
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxolyaivanovalion
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfadriantubila
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...amitlee9823
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxolyaivanovalion
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceDelhi Call girls
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 

Recently uploaded (20)

Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 

Newton Forward Interpolation

  • 1. PRACTICAL Name- Saloni Singhal M.Sc. (Statistics) II-Sem. Roll No: 2046398 Course- MATH-409 L Numerical Analysis Lab Submitted To: Dr. S.C. Pandey
  • 2. OBJECTIVE 1. Create an M-file to implement Newton Gregory Forward Interpolation. 1. Curve Fitting- Least Square nth order polynomial to data.
  • 3. Theory Then the process of knowing the value of f(x ) for some unknown value of x not explicitly given in the interval [a, b] is called interpolation. The value thus, determined is known as Interpolated value. This Newton Gregory Forward Interpolation formula is particularly useful for interpolating the values of f(x) near the beginning of the set of values given. h is called the interval of difference and u = ( x – a ) / h, Here a is the first term. Error term of the formula:
  • 4. Program clear; %input number of data points n= input('enter number of data points='); %input abscissa and ordinate value for a=1:n X(a)= input('enter X'+string(a)); end for b=1:n Y(b)= input('enter Y'+string(b)); end %enter the value to be interpolated using forward interpolation x=input('enter value of x to be interpolated'); %step size h and d gives the forward difference table h=X(2)-X(1); for i=1:n-1 d(i,1)=Y(i+1)-Y(i); end for j=2:n-1 for i=1:n-j d(i,j)=d(i+1,j-1)-d(i,j-1); end end
  • 5. Program Contd. P1=linspace(min(X),max(X),51); P2=zeros(51,1); for i=1:51 P2(i)=nf(P1(i),X,Y,n,d); end %plot for the given points plot(X,Y) hold on %plot for the interpoated curve plot(P1,P2) hold off d nf(x,X,Y,n,d) % function to calculate the forward inoterpolation function y=nf(u,X,Y,n,d) h=X(2)-X(1); p=(u-X(1))/h; prod=1; y=Y(1); for t=1:n-1 prod=prod*(p-t+1)/t; y=y+prod*d(1,t); end end
  • 6. Time Complexity 6 For the given program it is calculated as: For line 14= 2(n-1) since loop For line 16= (n-1)+1 since loop from 1:n-1 For line 18= 2(n-1)(n-2) for nested loop For line 24= 51(6n-3) since linspace generates 51 values(given) and min/max has time complexity n For line 36= (6n-3) since loop is from i to n-1 on adding the above dominant value is =O(n2) Big O notation is the most common metric for calculating time complexity. It describes the execution time of a task in relation to the number of steps required to complete it. We calculate the no of operations in respective loops and function. Big ‘O’ notation takes its dominant value
  • 8. Plot of the given data points and interpolated curve Reference: — Data Points plot —Interpolated curve
  • 9. Curve Fitting Syntax: p = polyfit(x,y,n) returns the coefficients for a polynomial p(x) of degree n that is a best fit (in a least-squares sense) for the data in y. The coefficients in p are in descending powers, and the length of p is n+1
  • 10. Conclusion • The interpolated value of the point is as shown in figure. • Polyfit (order 3) verifies the actual cubic formula for the given set of data points i.e. y= x³+2x-3.
  • 11. Caveats It can be observed that this formula is appropriate when the value to be interpolated (xs) lie almost in the beginning of the data table. More explicitly, when xs lies almost in the end of the data table then only first two or three terms of (1) can be taken into consideration to keep | s | < 1. and hence the result will not be sufficiently accurate. To overcome this problem, we go for next formula named Newton’s Backward difference formula.