Lagrange Interpolation With MATLAB Program Example

Lagrange's Interpolation Formula is used to determine the value of any function f(x), which is known at discrete points. That is if we have any function with its value at different points such as, at x=0, 1, 2... So using Lagrange's Interpolation Formula, we can determine the value of that function at any point.


We can derive the Lagrange's Interpolation formula by using Newton's divided difference formula. If f(x) is approximated with a Nth degree polynomial then the Nth divided difference of f(x) constant and (N+1)th divided difference is zero. That is


as we know Lagrange's interpolation is a Nth degree polynomial approximation to f(x) and the Nth degree polynomial passing through (N+1) points is unique hence the Lagrange's and Newton's divided difference approximations are one and the same. However, Lagrange's interpolation formula is very useful for the computer programming while Newton's difference formula is convenient for the hand calculations.

Question: Given set of values of x and y (5,12),(6,13),(9,14),(11,16)
Find the value of x corresponding to y=15 using lagrange interpolation


Tabular the given data:

y:  12  13  14  16

x:   5    6    9    11

Applying lagrange interpolation formula,





By putting y=15 we get x(15)=11.5

MATLAB Code for Lagrange Interpolation Formula

%Created by
%Created on 26 May 2013
%lagrange interpolation formula

% Question: Given set of values of x and y (5,12),(6,13),(9,14),(11,16)
% Find the value of x corresponding to y=15 using lagrange interpolation

clear all;
close all;
y=[12 13 14 16]; %Change here for different function
x=[5 6 9 11];

%Applying Lagrange's Interpolation:


fprintf('the value of x corresponding to y=15 is %f',m);

Image Format

[caption id="" align="aligncenter" width="490"]MATLAB code for lagrange interpolation MATLAB code for Lagrange interpolation[/caption]

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!