Difference between revisions of "Scilab/C4/Interpolation/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 57: Line 57:
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 7- Example
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 7- Example
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We are given the natural '''logarithm''' values for nine, nine point five and eleven.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We are given the '''natural logarithm''' values for nine, nine point five and eleven.  
  
  
We have to find the value of natural logarithm of nine point two.  
+
We have to find the value of '''natural logarithm''' of nine point two.  
  
  
Line 76: Line 76:
  
  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We define the function '''Lagrange''' with '''arguments x zero, x, f '''and''' n'''.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We define the '''function Lagrange''' with '''arguments x zero, x, f '''and''' n'''.  
  
 
'''X zero''' is the unknown '''interpolation point.'''
 
'''X zero''' is the unknown '''interpolation point.'''
Line 82: Line 82:
 
'''x''' is the '''vector '''containing the '''data points.'''
 
'''x''' is the '''vector '''containing the '''data points.'''
  
'''f''' is the '''vector '''containing the values of the '''function '''at correspoding '''data points.'''
+
'''f''' is the '''vector '''containing the values of the '''function '''at corresponding '''data points.'''
  
 
And '''n '''is the '''order '''of the '''interpolating polynomial'''.  
 
And '''n '''is the '''order '''of the '''interpolating polynomial'''.  
Line 118: Line 118:
  
  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we apply '''Lagrange''' '''interpolation''' '''formula''' to find the value of the '''numerator''' and '''denominator.'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we apply '''Lagrange interpolation formula''' to find the value of the '''numerator''' and '''denominator.'''
  
 
|-
 
|-
Line 139: Line 139:
  
  
We use '''L''' to find the value of the function '''y''' at the given data point. Finally we display the value of '''L''' and''' f of x.'''
+
We use '''L''' to find the value of the function '''y''' at the given data point.  
 +
 
 +
 
 +
Finally we display the value of '''L''' and''' f of x.'''
  
 
|-
 
|-
Line 147: Line 150:
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to Scilab console
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to Scilab console
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Switch to '''Scilab''' '''console''' to solve the example problem.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Switch to '''Scilab console''' to solve the example problem.
  
 
|-
 
|-
Line 155: Line 158:
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us define the '''data points vector'''.
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us define the '''data points vector'''.
  
On the console type,  
+
On the '''console''' type,  
  
 
'''x equal to open square bracket nine point zero comma nine point five comma eleven point zero close square bracket.'''
 
'''x equal to open square bracket nine point zero comma nine point five comma eleven point zero close square bracket.'''
Line 170: Line 173:
 
'''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'''
 
'''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'''
+
Press '''Enter'''.
  
 
|-
 
|-
Line 180: Line 183:
 
'''x zero equal to nine point two'''
 
'''x zero equal to nine point two'''
  
Press '''Enter'''
+
Press '''Enter'''.
  
 
|-
 
|-
Line 190: Line 193:
 
Type''' n equal to two'''
 
Type''' n equal to two'''
  
Press '''Enter'''
+
Press '''Enter'''.
  
 
|-
 
|-
Line 201: Line 204:
  
  
Press '''Enter'''
+
Press '''Enter'''.
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Show console
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Show console
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The value of the function '''y''' at '''x''' '''equal to nine point two''' is displayed.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The value of the function '''y''' at '''x equal to nine point two''' is displayed.  
  
 
|-
 
|-
Line 219: Line 222:
  
  
In spite of this, the same '''interpolating polynomial '''as in '''Lagrange method''' is generated.
+
In spite of this, the same '''interpolating polynomial''', as in '''Lagrange method''', is generated.
  
 
|-
 
|-

Revision as of 10:00, 26 December 2013

Title of script: Numerical Interpolation

Author: Shamika

Keywords: Interpolation, Lagrange method, Newton divided difference method


Visual Cue
Narration
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:
  • Develop Scilab code for different Numerical Interpolation algorithms
  • Calculate new value of function from given data points
Slide 3-System Requirement slide To record this tutorial, I am using
  • Ubuntu 12.04 as the operating system
  • and Scilab 5.3.3 version
Slide 4- Prerequisites slide To practise this tutorial, a learner should have
  • basic knowledge of Scilab
  • and should know Numerical Interpolation

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
  • constructing new data points
  • within the range of
  • a discrete set of known data points.

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.
  • Then we find the unique N order polynomial y of x which interpolates the data samples.
Slide 7- Example We are given the natural logarithm values for nine, nine point five and eleven.


We have to find the value of natural logarithm of nine point two.


Let us solve this problem using Lagrange interpolation method.

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 corresponding 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);


y = y + L(j)*f(j);

end

disp(L','L')

disp(f,'f(x)')


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


We use L to find the value of the function y at the given data point.


Finally we display the value of L and f of x.

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.


Press Enter

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


Press Enter.

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.


It uses lesser number of computation than Lagrange method.


In spite of this, the same interpolating polynomial, as in Lagrange method, is generated.

Slide 9- Example


Let us solve this example using divided difference method.


We are given the data points and the corresponding values of the function at those data points.


We have to find the value of the function at x equal to three.

Switch to Scilab editor


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


Open the file Newton underscore divided dot sci on Scilab Editor.

style="border-top:n

Contributors and Content Editors

Lavitha Pereira, Nancyvarkey