


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: INTRODUCTION TO NUMERICAL ANALYSIS; Subject: Mathematics; University: Oregon State University; Term: Spring 2001;
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Bent E. Petersen Filename: 351s2001_newton_divided_diff.mws
> restart;
The procedure divdiff() computes symbolic Newton divided differences recursively. Not much error checking is done so be careful. Note the use of a limit in the code. This allows us to compute the divided differences even when the nodes are not all distinct. The purpose of this procedure is to give you something to experiment with when you study Newton divided differences.
We use the divdiff() procedure to compute interpolation polynomials of functions in the procedure Ninterp() below. One nice feature is that Ninterp() does the right thing for the case of repeated nodes. Of course, Maple does have built-in interpolation, and one should use it. The Maple routine however works with lists of points, rather than functions. Thus Maple has no sensible way of handling repeated nodes, and returns an error in this case. We show below how the Maple routine can be used to interpolate functions and how to handle repeated nodes in that case simply by blowing up the repeated points and then passing to a limit.
**> divdiff:=proc(f)
local x; if nargs < 2 then ERROR(FAIL); fi; if nargs = 2 then RETURN(f(args[2])); else
limit((divdiff(f,args[3..nargs])-divdiff(f,x,args[3..nargs-1]))/(a rgs[nargs]-x),x=args[2]);
fi; end:**
Here's some examples:
> divdiff(f,a);
f ( a ) > divdiff(f,a,a);
D( ) f ( a ) > divdiff(f,a,b);
โ
f( b )โf( a ) โ b + a > divdiff(f,a,a,a);
( D(^2 ))( ) f ( a )
> divdiff(f,a,a,b);
f( b ) โ f( a )โ D( ) f ( a ) b +D( ) f ( a ) a ( โ b + a )^2 > divdiff(f,a,b,c);
โ
f( c ) b โ f( c ) a + f( b ) a โ f( b ) c + f( a ) c โf( a ) b ( โ c + b )( โ b + a )( a โ c )
Here's a routine to compute interpolation polynomials using Newton's divided differences formula. Note Maple does have built in support for interpolation. One should really use it. See below.
**> Ninterp:=proc(f,x)
local k,A,n; n:=3; if nargs < n then ERROR(FAIL); fi; if nargs = n then RETURN(x->f(args[3])); else A:=divdiff(f,args[n..nargs]); for k from nargs-1 to n by -1 do A:=A(x-args[k])+divdiff(f,args[n..k]); od; fi; A; end:*
Here's a few examples.
The tangent line
> Ninterp(f,t,a,a);
D( ) f ( a )( t โ a ) +f( a )
The parabola of contact order 2, that is, the Taylor polynomial at a of degree at most 2:
> Ninterp(f,t,a,a,a);
( D(^2 ))( ) f ( a )( t โ a ) D( ) f ( a ) ( t โ a ) f( a )
The parabola with order of contact 1 at a and order of contact 0 at b
> Ninterp(f,s,a,a,b);
It's not immediately obvious that p3 is equal to p, so let's look at the difference.
> simplify(p-p3);
0
Sure enough!
>