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.

Derivation

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

1

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

Solution

Tabular the given data:

y:  12  13  14  16

x:   5    6    9    11

Applying lagrange interpolation formula,

x(y)=(y-13)(y-14)(y-16)*5/(12-13)(12-14)(12-16)+

(y-12)(y-14)(y-16)*6/(13-12)(13-14)(13-16)+

(y-12)(y-13)(y-16)*9/(14-12)(14-13)(14-16)+

(y-12)(y-13)(y-14)*11/(16-12)(16-13)(16-14).

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

MATLAB Code for Lagrange Interpolation Formula

%Created by myclassbook.org
%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

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

%Applying Lagrange's Interpolation:
  ans1=((a-y(2))*(a-y(3))*(a-y(4)))*x(1)/((y(1)-y(2))*(y(1)-y(3))*(y(1)-y(4)));
  ans2=((a-y(1))*(a-y(3))*(a-y(4)))*x(2)/((y(2)-y(1))*(y(2)-y(3))*(y(2)-y(4)));
  ans3=((a-y(1))*(a-y(2))*(a-y(4)))*x(3)/((y(3)-y(1))*(y(3)-y(2))*(y(3)-y(4)));
  ans4=((a-y(1))*(a-y(2))*(a-y(3)))*x(4)/((y(4)-y(1))*(y(4)-y(2))*(y(4)-y(3)));

 m=ans1+ans2+ans3+ans4;

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

Image Format

MATLAB code for lagrange interpolation
MATLAB code for Lagrange interpolation

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!

Newton’s Forward Interpolation Formula with MATLAB Program

In everyday life, sometimes we may require finding some unknown value with the given set of observations. For example, the data available for the premium, payable for a policy of Rs.1000 at age x, is for every fifth year. Suppose, the data given is for the ages 30, 35, 40, 45, 50 and we are required to find the value of the premium at the age of 42 years, which is not directly given in the table. Here we use the method of estimating an unknown value within the range with the help of given set of observation which is known as interpolation.

Definition of Interpolation

Given the set of tabular values (x0, y0), (x1, y1),…,(xn, yn) satisfying the relation y=f(x) where the explicit nature of f(x) is not known, it is required to find a simpler function say ?(x), such that f(x) and ?(x) agree at the set of tabulated points. Such a process is called as interpolation.

If we know ‘n’ values of a function, we can get a polynomial of degree (n-1) whose graph passes through the corresponding points. Such a polynomial is used to estimate the values of the function at the values of x.

We will study two different interpolation formula based on finite differences when the values of x are equally spaced. The first formula is:

Newton’s forward difference interpolation formula:

The formula is stated as:

Newton’s forward difference interpolation formula

Where ‘a+ph’ is the value for which the value of the function f(x) is to be estimated. Here ‘a’ is the initial value of x and ‘h’ is the interval of differencing.

Question

The table gives the distance between nautical miles of the visible horizon for the given height in feet above the earth surface.  Find the value of y when x= 218 feet.

Newtons Forward Interpolation Formula
Newton’s Forward Interpolation Formula

MATLAB Program for Newtons Forward Interpolation Formula

Newtons Forward Interpolation Formula
Newton’s Forward Interpolation Formula

Newtons Forward Interpolation Formula
Newton’s Forward Interpolation Formula

You may also like

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!