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 Backward 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 useful
when the value of f(x) is required near the end of the table. h is
called the interval of difference and u = ( x – an ) / h, Here an is
last 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,j-1)-d(i-1,j-1);
end
end
Program Contd.
P1=linspace(min(X),max(X),51);
P2=zeros(51,1);
for i=1:51
P2(i)=nb(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
nb(x,X,Y,n,d)
% function to calculate the forward inoterpolation
function y=nb(u,X,Y,n,d)
h=X(2)-X(1);
p=(u-X(n))/h;
prod=1;
y=Y(1);
for t=1:n-1
prod=prod*(p+t-1)/t;
y=y+prod*d(n-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
>intbackward
enter number of data points=
5
enter X1
0
enter X2
1
enter X3
2
enter X4
3
enter X5
4
enter Y1
1
enter Y2
-1
enter Y3
1
enter Y4
-1
enter Y5
1
enter value of x to be interpolated
3.5
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 of degrees less than the number of data
points fits the given oscillatory curve X Y
0 1
1 -1
2 1
3 -1
4 1
Caveats
• Newton’s backward difference formula is best
suited when sx lies in the end of data table. Then, it can be
seen that for those values of sx , which lie almost in the
middle of the data table neither Forward or Backward
retains sufficient number of terms in the formula and thus
the interpolated value will not be sufficiently accurate.
• To overcome this problem we derive two more formulae
named as Stirling's formula and Bessel’s formula

More Related Content

Similar to Newton Backward Interpolation

Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxPJS KUMAR
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptxKokilaK25
 
1 chapter1 introduction
1 chapter1 introduction1 chapter1 introduction
1 chapter1 introductionSSE_AndyLi
 
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdfa) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdfpetercoiffeur18
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Deepak John
 
Intro. to computational Physics ch2.pdf
Intro. to computational Physics ch2.pdfIntro. to computational Physics ch2.pdf
Intro. to computational Physics ch2.pdfJifarRaya
 
Fortran chapter 2.pdf
Fortran chapter 2.pdfFortran chapter 2.pdf
Fortran chapter 2.pdfJifarRaya
 
Ee693 sept2014quizgt2
Ee693 sept2014quizgt2Ee693 sept2014quizgt2
Ee693 sept2014quizgt2Gopi Saiteja
 
chapter1.pdf ......................................
chapter1.pdf ......................................chapter1.pdf ......................................
chapter1.pdf ......................................nourhandardeer3
 
Unbounded Error Communication Complexity of XOR Functions
Unbounded Error Communication Complexity of XOR FunctionsUnbounded Error Communication Complexity of XOR Functions
Unbounded Error Communication Complexity of XOR Functionscseiitgn
 
A New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmA New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmJim Jimenez
 

Similar to Newton Backward Interpolation (20)

Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptx
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
Euler Method
Euler MethodEuler Method
Euler Method
 
1 chapter1 introduction
1 chapter1 introduction1 chapter1 introduction
1 chapter1 introduction
 
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdfa) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
 
Looping
LoopingLooping
Looping
 
algo_vc_lecture8.ppt
algo_vc_lecture8.pptalgo_vc_lecture8.ppt
algo_vc_lecture8.ppt
 
Es272 ch5b
Es272 ch5bEs272 ch5b
Es272 ch5b
 
parallel
parallelparallel
parallel
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 
Intro. to computational Physics ch2.pdf
Intro. to computational Physics ch2.pdfIntro. to computational Physics ch2.pdf
Intro. to computational Physics ch2.pdf
 
Fortran chapter 2.pdf
Fortran chapter 2.pdfFortran chapter 2.pdf
Fortran chapter 2.pdf
 
Ee693 sept2014quizgt2
Ee693 sept2014quizgt2Ee693 sept2014quizgt2
Ee693 sept2014quizgt2
 
chapter1.pdf ......................................
chapter1.pdf ......................................chapter1.pdf ......................................
chapter1.pdf ......................................
 
Unbounded Error Communication Complexity of XOR Functions
Unbounded Error Communication Complexity of XOR FunctionsUnbounded Error Communication Complexity of XOR Functions
Unbounded Error Communication Complexity of XOR Functions
 
Software Metrics
Software MetricsSoftware Metrics
Software Metrics
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
A New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmA New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring Algorithm
 

More from Saloni Singhal

Finite Difference Method
Finite Difference MethodFinite Difference Method
Finite Difference MethodSaloni Singhal
 
Simpson's Three-Eighth Method
Simpson's Three-Eighth MethodSimpson's Three-Eighth Method
Simpson's Three-Eighth MethodSaloni Singhal
 
Forward & Backward Differenece Table
Forward & Backward Differenece TableForward & Backward Differenece Table
Forward & Backward Differenece TableSaloni Singhal
 
Newton's Raphson method
Newton's Raphson methodNewton's Raphson method
Newton's Raphson methodSaloni Singhal
 
Fixed Point Interation
Fixed Point InterationFixed Point Interation
Fixed Point InterationSaloni Singhal
 
MARLAB codes for Gauss Seidel
MARLAB codes for Gauss SeidelMARLAB codes for Gauss Seidel
MARLAB codes for Gauss SeidelSaloni Singhal
 
MATLAB Codes for Jacobi method
MATLAB Codes for Jacobi methodMATLAB Codes for Jacobi method
MATLAB Codes for Jacobi methodSaloni Singhal
 
Gauss Elimination (without pivot).pptx
Gauss Elimination (without pivot).pptxGauss Elimination (without pivot).pptx
Gauss Elimination (without pivot).pptxSaloni Singhal
 
Gauss Elimination (With Partial Pivot)
Gauss Elimination (With Partial Pivot)Gauss Elimination (With Partial Pivot)
Gauss Elimination (With Partial Pivot)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
 
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
 
Fixed Point Interation
Fixed Point InterationFixed Point Interation
Fixed Point Interation
 
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

Zuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxZuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxolyaivanovalion
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
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
 
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
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
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
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...SUHANI PANDEY
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
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
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxolyaivanovalion
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Delhi Call girls
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero 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
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxolyaivanovalion
 

Recently uploaded (20)

Zuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxZuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptx
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
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...
 
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
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
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...
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
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
 
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
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero 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
 
(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
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 

Newton Backward 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 Backward 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 useful when the value of f(x) is required near the end of the table. h is called the interval of difference and u = ( x – an ) / h, Here an is last 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,j-1)-d(i-1,j-1); end end
  • 5. Program Contd. P1=linspace(min(X),max(X),51); P2=zeros(51,1); for i=1:51 P2(i)=nb(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 nb(x,X,Y,n,d) % function to calculate the forward inoterpolation function y=nb(u,X,Y,n,d) h=X(2)-X(1); p=(u-X(n))/h; prod=1; y=Y(1); for t=1:n-1 prod=prod*(p+t-1)/t; y=y+prod*d(n-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
  • 7. Output >intbackward enter number of data points= 5 enter X1 0 enter X2 1 enter X3 2 enter X4 3 enter X5 4 enter Y1 1 enter Y2 -1 enter Y3 1 enter Y4 -1 enter Y5 1 enter value of x to be interpolated 3.5
  • 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 of degrees less than the number of data points fits the given oscillatory curve X Y 0 1 1 -1 2 1 3 -1 4 1
  • 11. Caveats • Newton’s backward difference formula is best suited when sx lies in the end of data table. Then, it can be seen that for those values of sx , which lie almost in the middle of the data table neither Forward or Backward retains sufficient number of terms in the formula and thus the interpolated value will not be sufficiently accurate. • To overcome this problem we derive two more formulae named as Stirling's formula and Bessel’s formula