# FORTRAN - Neville's algorithm

Hello! Don't see a Fortran Language topic so I'm posting here! Soo
I'm Having a lil' problem here ... Trying to write a good Interpolation module using Neville's algorithm and it just seems like I can't  get a good interpolation for the function 1/sin(x).
Anyone have any ideas how to make an alternative subroutine or maybe what's wrong with mine? I'm posting here mine.
I know that interpolation 1/sin(x) is tricky beacuse the function has breaks around 0, pi, and 2 pi, but nevertheles
the numbers I'm getting have no sense
I'm trying to interpolate with 10th order polinomial and trying to interpolate 30 equidistant points in interval (0, 2*pi)
and all I'm getting out are really wierd numbers ... am I doing something wrong?

======================================
SUBROUTINE Neville(A, B, xm, xt, res, err)
REAL, dimension(:), intent( in ) :: A, B
REAL, intent( in ) :: xt
REAL, intent( out ) :: res, err
INTEGER, intent ( in ) :: xm
REAL, dimension(xm) :: P
INTEGER j,k
P(:) = B(:)
DO j=1, xm
DO k=1, xm - j
P(k)=((xt - A(k+j)) * P(k) + (A(k)-xt) * P(k+1))/(A(k)-A(k+j))
END DO
END DO
res=P(1)
err=P(1)-P(2)
return

END SUBROUTINE Neville
LVL 3
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Author Commented:
Ohh yes by the way ... It's Fortran 90!!
0
Software ArchitectCommented:
http://www.haoli.org/nr/bookfpdf/f3-1.pdf
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Numerical Recipes is actually a book from where I study numerical methods..
0
Commented:
I note that you are starting your counters at 1.  According to the following link, the algorithm was intended to be started from index 0, and suggests that if one wishes to start from 1, then of course adjustment to the boundary conditions at the top needs to be made.

http://www.cs.uaf.edu/~bueler/nevM.htm

If that's not the issue (I've only glanced at the coding), then let us know
0
Commented:
The link cited by jaime_olivares uses 1-based indexing, so I think my initial thought is wrong.
0
Author Commented:
Basicly with my Subroutine I get the same results as with the one written in Numerical Recipes F77, but I0m curious can someone test my subroutine with the function 1/sin(x) and others ... I mean write a main program and tell me their experience?... Have I really done something wrong or do the results really look that odd as mines.

moorhouselondon:
Unlike C or C++, Fortran starts it's counters(indexes) for Arrays with number 1 not 0. for example Array[1] is actually the first member of the array, not the second like in C or C++ .. like I said
0
Author Commented:
Figuered thatone out ... the main problem was the function that I was trying to interpolate ... soo the algorithm is basicly ok! But the function is not! :((

Thanx for trying guys!
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.