File Exchange

image thumbnail

Lagrange polynomial interpolation

version (582 Bytes) by Carlo Castoldi
Lagrange polynomial interpolation


Updated 31 Mar 2016

View License

Approx a point-defined function using Lagrange polinomial interpolation method

Cite As

Carlo Castoldi (2021). Lagrange polynomial interpolation (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (49)

fati didi

could you guys help me with that-->
Write a function interpol3 (n) which visualizes on the same figure in the interval [´ −5, 5]
the function f (x) = exp (x) and its polynomial interpolation built from n + 1
equidistant points defined on the interval [−1, 1].

Wajdi Hamama

It works for when fitting to original axis points, but as soon as I try to make it fit the data to a vector with a higher number of points, it is sensitive and it produces wild oscillations. I am applying it to a curve that goes on smoothly for a while and then kind of suddenly change the slope a couple of times. I suppose it was too much of a rate change for it.

Ruchi Agarwal

Please help me with the code of lagrange interpolation on image

Bo Li

maliha saleem

Caleb Miner

Rajesh Babu Tere

Amen Kenana

Jui Yang Wu

mohammadreza bayat

cyrine belhassen


Thanks, very good.

Bayram Can ?nce

good job

Marco Castelli

Very effective

Xiangbin Guo

if you can explain in the behind of the code,it will be much better,thank you very much


I do not understand why you need ",2" when you are determining the size of pointx. Why can't you just code n=size(pointx)? I am new to matlab, can someone explain?


To answer some of those questions here is an example of input:
where [x0,...,xn] is pseudo-code for representing the x values as an array and [f(x0),...,f(xn)]. Then try to plot that lagrange against the function you are interpolating and you should see the desired results.


Juan Camilo Medina

Simple yet functional code. Thanks

madinatul munawaroh

anyone can give me example how to use it?
i need it for my study...

naser Rashwan

how to represent x, i represent the x as [1 0] but it did not give the right answer


and what exactly do you have to give as input??

pamonz wank

sanjay zine

Satya Sudhakar Yedlapalli

Can be made as a basic matlab function

mahesh nair

LAY Nary

I don't know

Pier Francesco Maria Gatti

what is x? :D

hira manzoor

Arc .

Very usefull - I need it for convertion to java code.

imran aslam

John D'Errico

Lagrange interpolation is one of those interpolation methods that beginning textbooks include, along the way to showing you some useful methods. I imagine the textbook authors want to show you some of the history of interpolation. The fact is, high order Lagrange interpolation of this ilk was a only ever a good idea BACK IN the time of Lagrange. There has actually been progress in knowledge since then. (Surprise!) This is a terribly poor choice of interpolation method today.

In general, splines or other methods like them (PCHIP) will be less likely to introduce interpolation artifacts, oscillations, etc. Splines will be FAR less sensitive to tiny amounts of noise than will a high order Lagrange.

Even if I choose to disregard the method it implements,
the code itself is poorly implemented. It is triply looped - totally unvectorized. Expect it to be slow and if you have a large number of points, it will take more memory than need be.

If you need to use an interpolation tool, start with interp1, spline, or pchip, or look to the splines toolbox for more choices.

Jose Garcia

haris ahmad

i am a student of electronics engr and hav to do numerical diff using lagrange

Haroon Awais

good work, but it is better to use Matlab "interp1" function.

Jev Jeg

frederico schultz

muito obrigado...boa sorte




Great job!!! Good work!


Very Good

bill cosby

Thank you for a great program

im einnor

flawless program!

Aleksey Rozsdobudko

what did u write?????? It can write even a child!!!!
dont use such words as "for","while" and anything like that in the matlab cos it's STUPPIDNESS!!!!!!

sima asgari


Sukant Gupta

t t


oziel alcocer

keene rolph

The source code is very is good for research especially for mathematics purpose.

steve xia

MATLAB Release Compatibility
Created with R10
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!