MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

### Discover what MATLAB® can do for your career.

Asked by zen dyka on 19 May 2013

write a computer program for interpolation by neville's method. the program must be able to compute the interpolant at several user-specified values of x. Test the program by determining y at x=1.1, 1.2, 1.3 from the following data:

x       -2.0          -0.1        -1.5            0.5          -0.6          2.2            1.0          1.8

y    2.2796    1.0025    1.6467    1.0635    1.0920    2.6291    1.2661    1.9896

## Products

No products are associated with this question.

Answer by Roger Stafford on 19 May 2013
Edited by Roger Stafford on 19 May 2013

My advice would be to first take an example with, say, just three values of x and of y. Forget about computers for a minute and carry out the procedures of Neville's algorithm by hand (or hand calculator) as explained in an article like http://en.wikipedia.org/wiki/Neville's_algorithm. You can't do the programming until you fully understand the algorithm.

The next stage is to realize that you have a process with an outer loop and an inner one. At each step of the outer loop the inner loop has one less step to take, until at the final outer loop step there is only one inner loop step remaining, and that one yields the answer. If you are using matlab that should of course suggest two nested for-loops. By carefully translating what you did earlier by hand over to computer action you can write these two loops.

Note that you are under no obligation to use the same notation given in the Wikipedia article. In fact that is highly inadvisable. In particular recall that matlab indices cannot be zero but must start with one.

As a final stage to impress your teacher you can show how that inner loop can rather easily be vectorized.