Scilab/C4/Interpolation/English
Title of script: Numerical Interpolation
Author: Shamika
Keywords: Interpolation, Lagrange method, Newton divided difference method



Slide 1  Dear Friends,
Welcome to the Spoken Tutorial on “Numerical Interpolation” 
Slide 2 Learning Objective Slide  At the end of this tutorial, you will learn how to:

Slide 3System Requirement slide  To record this tutorial, I am using

Slide 4 Prerequisites slide  To practise this tutorial, a learner should have
To learn Scilab, please refer to the relevant tutorials available on the Spoken Tutorial website. 
Slide 5 Numerical Interpolation  Numerical interpolation is a method of
We can solve interpolation problems using numerical methods. 
Slide 6 Lagrange Interpolation  In Lagrange interpolation, we pass a polynomial of degree N – 1 through N points.

Slide 7 Example  We are given the natural logarithm values for nine, nine point five and eleven.
Change made. natural logarithm of nine point two.

Show Lagrange.sci code on Scilab editor

Let us look at the code for Lagrange interpolation. 
Highlight
Lagrange(x0, x,f, n)

We define the function Lagrange with arguments x zero, x, f and n.
X zero is the unknown interpolation point. x is the vector containing the data points. f is the vector containing the values of the function at correspoding data points. And n is the order of the interpolating polynomial. 
Highlight
m = n + 1; N = ones(1,m);

We use n to initialize m and vector N.
The order of the interpolating polynomail determines the number of nodes created. 
Highlight
for j = 1:m for k = 1:m if (k<>j) then N(j) = N(j)*(x0  x(k)) D(j) = D(j)*(x(j)  x(k)) end end

Then we apply Lagrange interpolation formula to find the value of the numerator and denominator. 
Highlight
L(j) = N(j)/D(j);
end disp(L','L') disp(f,'f(x)')

Then we divide the numerator and denominator to get the value of L.

Click on Execute and select Save and Execute  Let us save and execute the file. 
Switch to Scilab console  Switch to Scilab console to solve the example problem. 
Type on console
x=[9.0,9.5,11.0] 
Let us define the data points vector.
On the console type, x equal to open square bracket nine point zero comma nine point five comma eleven point zero close square bracket.

Type on console
f=[2.1972,2.2513,2.3979] 
Then type
f equal to open square bracket two point one nine seven two comma two point two five one three comma two point three nine seven nine close square bracket Press Enter 
Type on console
x0=9.2 
Then type
x zero equal to nine point two Press Enter 
Type on console
n=2 
Let us use a quadratic polynomial interpolating polynomial.
Type n equal to two Press Enter 
Type on console
y = Lagrange(x0, x,f, n) 
To call the function, type
y equal to Lagrange open paranthesis x zero comma x comma f comma n close paranthesis

Show console  The value of the function y at x equal to nine point two is displayed. 
Let us look at Newton's Divided Difference Method.  
Slide 8 Newton's Divided Difference Method  In this method, divided differences recursive method is used.

Slide 9 Example

Let us solve this example using divided difference method.

Switch to Scilab editor

Let us look at the code for Newton Divided difference method.

Highlight
Newton_Divided(x,f,x0)

We define the function Newton underscore Divided with arguments x, f and x zero.

Highlight
n = length(x);

We find the length of vector and then equate it to n. 
Highlight
a(1) = f(1);

The first value of vector is equated to a of one. 
Highlight
for k = 1 : n  1 D(k, 1) = (f(k+1)  f(k))/(x(k+1)  x(k)); end for j = 2:n1 for k = 1:nj D(k, j) = (D(k+1, j1)  D(k, j1))/(x(k+j)  x(k)) end end disp(D, 'The Divided Difference Table')

Then we apply divided difference algorithm and compute the divided difference table 
Highlight
Df(1) = 1; c(1) = a(1);
Df(j)=(x0  x(j1)).*Df(j1); c(j) = a(j).*Df(j); end

Then we find the coefficient list of the Newton polynomial 
Highlight
IP = sum(c);

We sum the coefficient list to find the value of the function at given data point. 
Click on Execute and select Save and Execute  Save and execute the file Newton underscore divided dot sci. 
Switch to Scilab console  Switch to Scilab console 
Type clc  Clear the screen by typing c l c.
Press Enter 
Type on console
x=[2,2.5,3.25,4] 
Let us enter the data points vector
Type x equal to open square bracket two comma two point five comma three point two five comma four close square bracket

Type on console
f=[0.5,0.4,0.3077,0.25] 
Then type values of the function
Type f equal to open square bracket zero point five comma zero point four comma zero point three zero seven seven comma zero point two five close square bracket Press Enter 
Type on console
x0=3 
Type x zero equal to three
Press Enter 
Type on console
IP = Newton_Divided(x,f,x0) 
Then call the function by typing
i p equal to Newton underscore divided open paranthesis x comma f comma x zero close paranthesis Press Enter 
Show console  The value of y at x equal to three is shown. 
Slide 9 Summary  Let us summarize this tutorial.

Slide 10 Assignment  Solve this problem on your own using Lagrange method and Newton's divided difference method. 
Show Slide 11
Title: About the Spoken Tutorial Project

* About the Spoken Tutorial Project

Show Slide 12
Title: Spoken Tutorial Workshops The Spoken Tutorial Project Team

The Spoken Tutorial Project Team

Show Slide 13
Title: Acknowledgement

* Spoken Tutorial Project is a part of the Talk to a Teacher project

This is Ashwini Patil signing off. Thanks for joining. 