Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

extrapolation of polint

133 views
Skip to first unread message

Rudra Banerjee

unread,
Aug 18, 2013, 3:46:55 PM8/18/13
to
Hi,
this is a straight (almost) copy of polint code from nr (page 103, 2nd
ed, fortran version)
Program polint
Implicit None
integer,parameter :: n=8
real(4) :: dy,x,y,xa(n),ya(n)
integer :: i,j,m,ns
real(4) :: den,dif,dift,ho,hp,w,c(n),d(n)
x=0.642
open(11,file="polint.in",status="old")
do i=1,n
read(11,*)xa(i),ya(i)
write(*,*)xa(i),ya(i)
end do

ns=1
dif=abs(x-xa(1))
do i=1,n
dift=abs(x-xa(i))
if (dift < dif) then
ns=i
dif=dift
end if
c(i)=ya(i)
d(i)=ya(i)
end do
y=ya(ns)
ns=ns-1
do m=1,n-1
do i=1,n-m
ho=xa(i)-x
hp=xa(i+m)-x
w=c(i+1)-d(i)
den=ho-hp
den=w/den
d(i)=hp*den
c(i)=ho*den
end do
if ((2*ns)< (n-m)) then
dy=c(ns+1)
else
dy=d(ns)
ns=ns-1
end if
y=y+dy
end do
write(*,*)x,y
End Program polint

The problem is while it is doing well for interpolation, fails badly
with extrapolation. Here is a sample data set:
$cat polint.in
0.28001 .53731472
0.34274 .67163649
0.40071 .77802463
0.41041 .80009080
0.45987 .90000000
0.48014 .93333334
0.49642 .96000000
0.49948 .96666667

Any help please?


Arjan

unread,
Aug 18, 2013, 4:46:06 PM8/18/13
to
> Any help please?


Maybe a bit blunt, but straight from my heart: don't extrapolate! Extrapolation is the devil herself! Have you already checked what happens with your extrapolation when you increase the order of your polynomial? Make plots of these extrapolating functions and allow yourself to laugh!

Please get some understanding of the behaviour of your function in the domain where you want to use it and use this knowledge to guide your estimate.

Arjan

Richard Maine

unread,
Aug 18, 2013, 4:58:56 PM8/18/13
to
Arjan <arjan.v...@rivm.nl> wrote:

> > Any help please?
>
> Maybe a bit blunt, but straight from my heart: don't extrapolate!
> Extrapolation is the devil herself! Have you already checked what
> happens with your extrapolation when you increase the order of your
> polynomial? Make plots of these extrapolating functions and allow
> yourself to laugh!

And note that this isn't actually a Fortran language issue. It's just
math. You'll get the same behavior independent of the language of
implementation.

--
Richard Maine
email: last name at domain . net
domain: summer-triangle

glen herrmannsfeldt

unread,
Aug 18, 2013, 6:38:19 PM8/18/13
to
Richard Maine <nos...@see.signature> wrote:
> Arjan <arjan.v...@rivm.nl> wrote:

>> > Any help please?

>> Maybe a bit blunt, but straight from my heart: don't extrapolate!
>> Extrapolation is the devil herself! Have you already checked what
>> happens with your extrapolation when you increase the order of your
>> polynomial? Make plots of these extrapolating functions and allow
>> yourself to laugh!

> And note that this isn't actually a Fortran language issue. It's just
> math. You'll get the same behavior independent of the language of
> implementation.

Well, yes, but pretty often discussion of numerical analysis
problems start a useful and productive discussion here, unlike
some other groups.

But in this case I have to agree, there isn't much to say.

Assuming that the extrapolation is consistent with what the
routine does for interpolation, it is the responsibility of
the user to make sure it does what is desired, or find one
that does the expected thing.

A program that does linear interpolation could be expected to do
linear extrapolation based on the last two points (or the first
two on the other end). If it used points outside the array to do
extrapolation, then that would be a bug.

-- glen

Gordon Sande

unread,
Aug 18, 2013, 6:51:13 PM8/18/13
to
On 2013-08-18 19:46:55 +0000, Rudra Banerjee said:

> Hi,this is a straight (almost) copy of polint code from nr (page 103, 2nd
> $cat polint.in0.28001 .53731472
> 0.34274 .67163649
> 0.40071 .77802463
> 0.41041 .80009080
> 0.45987 .90000000
> 0.48014 .93333334
> 0.49642 .96000000
> 0.49948 .96666667
>
> Any help please?

What book? About what method?

If you were to study any mathematics about functional fitting you would
find that
the fit will oscillate about the target INSIDE some range and then
"explode" once
it gets outside that range. Absolutely expected. The math dates to 1850 or so.

Plot a Tchebycheff (many alternate spellings) polynomial and you will
see that it
is very well behaved on -1 to +1 but if you plot from -10 to +10 you
will see the
values grow greatly outside the central -1 to +1. In fact there are theorems to
the effect that the Tchebycheff polynomials are the most extreme at
this becuase
they are the best behaved in the middle.

Any introductory text on numerical analysis should give some
commentary. A second
course will start to cite the theorems.




Arjan

unread,
Aug 19, 2013, 4:38:40 AM8/19/13
to
> Any help please?

Y = 1.95 X seems to catch the coarse behaviour...


A.

Terence

unread,
Aug 19, 2013, 5:53:30 AM8/19/13
to
Extrapolation is the use of a series of given points to define known points
on a suspected curve or straight line, to estimate the positions of new
points outside the polihedral area defined by the given points.
Since any extrapolated point is outside the given area of knowledge, an
error in judgement will always occur. A least squares fit is usually the
best way to reduce the error to a small range, within a calculable degree of
confidence.
So don't use interpolation methods for extrapolation.



Rudra Banerjee

unread,
Aug 19, 2013, 6:37:31 AM8/19/13
to
On Mon, 2013-08-19 at 19:53 +1000, Terence wrote:
> So don't use interpolation methods for extrapolation.
>
Terence, Arjen and other,
Thanks for your response.
Actually, Numerical Recipes (nr in my original post, sorry that I did
not elaborate) says "Routines given for interpolation are also routine
for extrapolation"(Page 101 of 2nd ed, fortran) and that was my
assumption.
Also, just at the beginning of the polint routine (page 103) they says
it is "for polynomial interpolation or extrapolation". Is this a mistake
from their part? or as Glen said, its my mistake?


Rudra Banerjee

unread,
Aug 19, 2013, 6:40:10 AM8/19/13
to
On Sun, 2013-08-18 at 13:58 -0700, Richard Maine wrote:
>
> And note that this isn't actually a Fortran language issue. It's just
> math. You'll get the same behavior independent of the language of
> implementation.
>
Richard,
I always respect your views. But yes, here I am looking for a
explanation of the method, not a language specific implementation.
Hope, this is inside the scope of the group.
Regards,

e p chandler

unread,
Aug 19, 2013, 2:29:55 PM8/19/13
to
AFAIK, polynomials are not much good for fitting curves unless you know that the data points are described by a polynomial and what is the degree of the polynomial. [If you have a cloud of points that do not exactly fit on the curve, then you get into least squares methods, as Terence mentions.]

I can think of two quick ways to see how the fit works over a small interval and beyond that interval. Look at the graphs of a line, parabola, cubic, and higher degree curves. They get more and more twisted as the degree increases as they have more critical points. Secondly, consider a Taylor series expansion of a function. Mainly it shows how closely a function can be approximated but it is not a practical way of calculating special functions except over a small range [f(x+h)] for very small h.

One of the FAQs in this newsgroup is about programs from Numerical Recipes. The usual advice here (mildly stated) is to use them with caution, more so to develop an understanding of the methods involved.[So cautions in using NR are IMO on topic here. :-)]

--- e



glen herrmannsfeldt

unread,
Aug 19, 2013, 2:36:13 PM8/19/13
to
Well, for many years "interpolation" meant "linear interpolation"
and linear extrapolation is pretty well defined, though maybe not
so useful.

Interpolation relies on the function being sufficiently smooth over
the region of interest. Extrapolation relies on much more, and so
must be used more carefully.

-- glen

Richard Maine

unread,
Aug 19, 2013, 2:40:14 PM8/19/13
to
e p chandler <ep...@juno.com> wrote:

> AFAIK, polynomials are not much good for fitting curves unless you know
> that the data points are described by a polynomial and what is the
> degree of the polynomial. [If you have a cloud of points that do not
> exactly fit on the curve, then you get into least squares methods, as
> Terence mentions.]

Interpolation methods usually are for data points that exactly fit on a
curve. If you use that kind of method with measured data, which wil
invariably have some error, even if small, the interpolation methods
often are horribly ill behaved in that they make the curve do all kinds
of messy gyrations to force an exact fit. Those gyrations get even worse
when used for extrapolation.

Methods like least squares fits can be reasonable, but even there, you
will get horrible results if you use too high an order.

e p chandler

unread,
Aug 19, 2013, 3:12:51 PM8/19/13
to
On Monday, August 19, 2013 2:36:13 PM UTC-4, glen herrmannsfeldt wrote:
> Rudra Banerjee wrote:
> > On Mon, 2013-08-19 at 19:53 +1000, Terence wrote:
> >> So don't use interpolation methods for extrapolation.

> > Thanks for your response.
> > Actually, Numerical Recipes (nr in my original post, sorry that I did
> > not elaborate) says "Routines given for interpolation are also routine
> > for extrapolation"(Page 101 of 2nd ed, fortran) and that was my
> > assumption.

[snip]

> Well, for many years "interpolation" meant "linear interpolation"

[putting on rose colored backward-looking glasses]
And I remember those days well, using log and trig tables - mentally interpolating between table entries.

[OT]Not that I really wish students to go back to those days, but I think that some sense, partially kinesthetic, has been lost. I do think that students miss out by not plotting data by hand, not only from a visceral sense, but also from being forced by the economics of calculation to start with simple models and to spend more time selecting which models might be appropriate.

--- e

glen herrmannsfeldt

unread,
Aug 19, 2013, 7:18:04 PM8/19/13
to
e p chandler <ep...@juno.com> wrote:

(snip, I wrote)
>> Well, for many years "interpolation" meant "linear interpolation"

> [putting on rose colored backward-looking glasses]
> And I remember those days well, using log and trig tables -
> mentally interpolating between table entries.

> [OT]Not that I really wish students to go back to those days,
> but I think that some sense, partially kinesthetic, has been lost.
> I do think that students miss out by not plotting data by hand,
> not only from a visceral sense, but also from being forced by
> the economics of calculation to start with simple models and
> to spend more time selecting which models might be appropriate.

I think I agree, but there are so many things to learn today in
the same amount of time. College is still four years, as it has
been for a long time.

Reminds me, though, before they taught us least-squares, they
taught the previous way to do it. Plot the points, draw what
looks like a nice line through the points, find its slope and
intercept, subtract that line from the original and make a new
plot of the difference between the data and the first line.

Normally, it will have a much expanded scale on the Y axis,
and you can easily see any small deviation from the best fit.

Then we got out our recently available programmable calculator
(days of the HP-25C) and did a least-squares fit.

But they probably don't teach that anymore, either.

-- glen

0 new messages