1

I wrote this Neville's method in R, but I am familiar with Matlab too. So any of your comments in either R or Matlab are really great to me.

Base on these data points:

x= 1.5
xi = c(1,1.3,1.6,1.9,2.2)
fi = c(0.7651977, 0.6200860, 0.4554022, 0.2818186, 0.1103623)

and below is my script in R:

neville <- function(x,xi,fi){
  n <- length(xi) - 1
  Q <- matrix(0, n+1, n+1)
  Q[,1] = fi
  for (i in 1:n) {
    for (j in 1:i){
       Q[i+1,j+1] <- ((x - xi[i-j +1])*Q[i+1,j] - (x - xi[i+1])
                 *Q[i,j])/(xi[i+1] - xi[i-j+1])
    }
  }
  return (Q)
}

Clearly that, my output is in the form of matrix. So, can anyone show me how to plot the interpolation for this Neville's method to represent my xi and fi points ?

Alexander
  • 282
  • 1
  • 4
  • 13
  • 1
    Anything you've already tried yourself? Why did it not work? – Heroka Oct 22 '15 at 08:54
  • I have tried plot(xi, pi, type = 'p', xi, a = neville(x,xi,pi), type = 'l'), but then I realized that they don't have the same length. – Alexander Oct 22 '15 at 08:58
  • Is pi the same as fi? And where is x? Please consider reading this: [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Heroka Oct 22 '15 at 09:04
  • oh, that is 'fi'. Sorry, it was my typo and in this case, x = 1.5 – Alexander Oct 22 '15 at 09:07
  • Do you have an example of what such a plot should look like? I'm not familiar with Neville's method, and having a hard time visualizing it. – Heroka Oct 22 '15 at 09:14
  • 1
    Your calculation gives different results than the `neville` function in `pracma` package. –  Oct 22 '15 at 09:24
  • @Pascal: i used the algorithm in Numerical analysis by Burnden – Alexander Oct 22 '15 at 15:34
  • It doesn't mean your implementation is correct. –  Oct 22 '15 at 16:03
  • in that case, I will check it later. But, if you know how to plot the Neville's method. Can you please show me how? – Alexander Oct 22 '15 at 17:34

0 Answers0