Difference between revisions of "Scilab/C4/Interpolation/English"
(Created page with ''''Title of script''': '''Numerical Interpolation''' '''Author: Shamika''' '''Keywords: Interpolation, Lagrange method, Newton divided difference method''' {| style="border-s…') |
Nancyvarkey (Talk | contribs) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
'''Author: Shamika''' | '''Author: Shamika''' | ||
− | '''Keywords: Interpolation, Lagrange method, Newton | + | '''Keywords: Interpolation, Lagrange method, Newton Divided Difference method''' |
Line 20: | Line 20: | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| At the end of this tutorial, you will learn how to: | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| At the end of this tutorial, you will learn how to: | ||
− | * Develop Scilab code for different Numerical Interpolation algorithms | + | * Develop '''Scilab code''' for different '''Numerical Interpolation algorithms''' |
− | * Calculate new value of function from given data points | + | * Calculate new value of '''function''' from given '''data points''' |
− | + | ||
− | + | ||
|- | |- | ||
Line 31: | Line 29: | ||
* '''Ubuntu 12.04''' as the operating system | * '''Ubuntu 12.04''' as the operating system | ||
* and '''Scilab 5.3.3''' version | * and '''Scilab 5.3.3''' version | ||
− | |||
− | |||
|- | |- | ||
Line 51: | Line 47: | ||
* a '''discrete set''' of known '''data points'''. | * a '''discrete set''' of known '''data points'''. | ||
− | We can solve '''interpolation''' problems using numerical methods. | + | We can solve '''interpolation''' problems using '''numerical methods'''. |
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 6- Lagrange Interpolation | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 6- Lagrange Interpolation | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| In '''Lagrange interpolation''', | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| 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''' | |
− | Then we find the unique '''N''' '''order polynomial y of x''' which '''interpolates''' the '''data''' samples. | + | * which '''interpolates''' the '''data''' samples. |
|- | |- | ||
Line 65: | Line 61: | ||
− | We have to find the value | + | We have to find the value of '''natural logarithm''' of nine point two. |
− | + | ||
− | + | ||
Line 74: | Line 68: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Show Lagrange.sci code on Scilab editor | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Show Lagrange.sci code on Scilab editor | ||
− | |||
− | |||
− | |||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us look at the code for '''Lagrange interpolation.''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us look at the code for '''Lagrange interpolation.''' | ||
Line 88: | Line 79: | ||
| 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.''' |
− | '''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 correspoding '''data points.''' |
− | And '''n '''is the '''order '''of the '''interpolating polynomial'''. | + | *And '''n '''is the '''order '''of the '''interpolating polynomial'''. |
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight | ||
− | m | + | m = n + 1<nowiki>;</nowiki> |
− | + | ||
− | + | ||
+ | N = ones(1,m)<nowiki>;</nowiki> | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We use '''n''' to initialize '''m''' and '''vector N.''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We use '''n''' to initialize '''m''' and '''vector N.''' | ||
− | The order of the '''interpolating | + | The order of the '''interpolating polynomial '''determines the number of '''nodes '''created. |
|- | |- | ||
Line 128: | 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 | + | | 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:none;padding:0.097cm;"| Highlight | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight | ||
− | L(j) | + | L(j) = N(j)/D(j); |
− | y | + | y = y + L(j)<nowiki>*</nowiki>f(j); |
end | end | ||
Line 149: | Line 141: | ||
− | 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 157: | Line 151: | ||
|- | |- | ||
| 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 | + | | 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 165: | Line 159: | ||
| 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 211: | Line 205: | ||
− | 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 | + | | 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 223: | Line 217: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 8- Newton's Divided Difference Method | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 8- Newton's Divided Difference Method | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| In this method, ''' | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| In this method, '''Divided Differences recursive method '''is used. |
Line 229: | Line 223: | ||
− | 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. |
|- | |- | ||
Line 236: | Line 230: | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us solve this example using ''' | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| 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 are given |
+ | *the '''data points''' and | ||
+ | *the corresponding values of the '''function''' | ||
+ | *at those '''data points'''. | ||
Line 249: | Line 246: | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us look at the code for '''Newton Divided | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us look at the code for '''Newton Divided Difference method'''. |
− | Open the file '''Newton underscore | + | Open the file '''Newton underscore Divided dot sci''' on '''Scilab Editor.''' |
|- | |- | ||
Line 264: | Line 261: | ||
− | ''' | + | *'''x''' is a '''vector''' containing the '''data points''', |
+ | '''f''' is the corresponding '''function''' *'''value''' and | ||
+ | *''' x zero''' is the unknown '''interpolation point'''. | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight | ||
− | n | + | n = length(x); |
− | + | ||
− | + | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We find the length of '''vector''' and then equate it to''' n.''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We find the length of '''vector''' and then equate it to''' n.''' | ||
Line 278: | Line 275: | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight | ||
− | a(1) | + | a(1) = f(1); |
− | + | ||
− | + | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The first value of '''vector''' is equated to '''a of one.''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The first value of '''vector''' is equated to '''a of one.''' | ||
Line 287: | Line 282: | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight | ||
− | for k | + | for k = 1 : n - 1 |
D(k, 1) <nowiki>=</nowiki> (f(k+1) - f(k))/(x(k+1) - x(k))<nowiki>;</nowiki> | D(k, 1) <nowiki>=</nowiki> (f(k+1) - f(k))/(x(k+1) - x(k))<nowiki>;</nowiki> | ||
Line 307: | Line 302: | ||
− | | 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 '''divided difference algorithm''' and compute the '''divided difference table''' | + | | 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 '''divided difference algorithm''' and compute the '''divided difference table'''. |
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight | ||
− | Df(1) | + | Df(1) = 1; |
− | c(1) | + | c(1) = a(1); |
− | for j | + | for j = 2 : n |
− | Df(j) | + | Df(j)=(x0 - x(j-1)).*Df(j-1); |
− | c(j) | + | c(j) = a(j).*Df(j); |
end | end | ||
Line 333: | Line 328: | ||
IP <nowiki>=</nowiki> sum(c)<nowiki>;</nowiki> | IP <nowiki>=</nowiki> sum(c)<nowiki>;</nowiki> | ||
+ | |||
+ | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| | ||
+ | *We sum the '''coefficient list ''' | ||
+ | *to find the value of the '''function''' | ||
+ | *at given '''data point.''' | ||
+ | |||
− | |||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Click on Execute and select Save and Execute | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Click on Execute and select Save and Execute | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Save and execute the file '''Newton underscore | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Save and execute the file '''Newton underscore Divided dot sci. ''' |
|- | |- | ||
Line 350: | Line 350: | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Clear the screen by typing '''c l c'''. | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Clear the screen by typing '''c l c'''. | ||
− | Press '''Enter''' | + | Press '''Enter'''. |
|- | |- | ||
Line 363: | Line 363: | ||
− | Press '''Enter''' | + | Press '''Enter'''. |
|- | |- | ||
Line 371: | Line 371: | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then type values of the '''function''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then type values of the '''function''' | ||
− | + | '''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''' | + | Press '''Enter'''. |
|- | |- | ||
Line 381: | Line 381: | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Type '''x zero equal to three''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Type '''x zero equal to three''' | ||
− | Press '''Enter''' | + | Press '''Enter'''. |
|- | |- | ||
Line 389: | Line 389: | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then call the '''function '''by typing | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then call the '''function '''by typing | ||
− | '''i p equal to Newton underscore | + | '''i p equal to Newton underscore Divided open parenthesis x comma f comma x zero close parenthesis''' |
− | 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 '''y | + | | 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 '''y at x equal to three '''is shown. |
|- | |- | ||
Line 402: | Line 402: | ||
− | In this tutorial we have learnt to develop '''Scilab '''code for '''interpolation methods. ''' | + | In this tutorial, |
+ | |||
+ | we have learnt to develop '''Scilab '''code for '''interpolation methods. ''' | ||
Line 409: | Line 411: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 10- Assignment | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 10- Assignment | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Solve this problem on your own using Lagrange method and Newton's | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Solve this problem on your own using '''Lagrange method''' and '''Newton's Divided Difference method'''. |
|- | |- | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| |
− | + | ||
− | + | ||
* Watch the video available at [http://spoken-tutorial.org/What_is_a_Spoken_Tutorial http://spoken-tutorial.org/What_is_a_Spoken_Tutorial] | * Watch the video available at [http://spoken-tutorial.org/What_is_a_Spoken_Tutorial http://spoken-tutorial.org/What_is_a_Spoken_Tutorial] | ||
Line 430: | Line 430: | ||
* If you do not have good bandwidth, you can download and watch it | * If you do not have good bandwidth, you can download and watch it | ||
− | |||
− | |||
|- | |- | ||
Line 474: | Line 472: | ||
* It is supported by the National Mission on Education through ICT, MHRD, Government of India | * It is supported by the National Mission on Education through ICT, MHRD, Government of India | ||
* More information on this Mission is available at | * More information on this Mission is available at | ||
− | * spoken hyphen tutorial dot org slash NMEICT hyphen Intro | + | * spoken hyphen tutorial dot org slash NMEICT hyphen Intro |
− | + | ||
− | + | ||
− | + | ||
|- | |- |
Latest revision as of 22:34, 1 February 2014
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 3-System 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,
|
Slide 7- Example | We are given the natural logarithm values for nine, nine point five and eleven.
|
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.
|
Highlight
m = n + 1; N = ones(1,m);
|
We use n to initialize m and vector N.
The order of the interpolating polynomial 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,
|
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.
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.
|
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.
f is the corresponding function *value and
|
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:n-1 for k = 1:n-j D(k, j) = (D(k+1, j-1) - D(k, j-1))/(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(j-1)).*Df(j-1); c(j) = a(j).*Df(j); end
|
Then we find the coefficient list of the Newton polynomial |
Highlight
IP = sum(c); |
|
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
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 parenthesis x comma f comma x zero close parenthesis Press Enter. |
Show console | The value of y at x equal to three is shown. |
Slide 9- Summary | Let us summarize this tutorial.
we have learnt to develop Scilab code for interpolation methods.
|
Slide 10- Assignment | Solve this problem on your own using Lagrange method and Newton's Divided Difference method. |
|
* 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. |