The two inputs X and Y are vectors defining a set of N points. The function uses Lagrange's method to find the N-1th order polynomial that passes through all these points, and returns in P the N coefficients defining that polynomial. Then, polyval(P,X) = Y.
R returns the x co-ordinates of the N-1 extrema/inflection points of the resulting polynomial (roots of its derivative), and S returns the value of the polynomial at those points.
For a general-purpose way to find a smooth curve connecting points, you probably want to use SPLINE instead.
Can someone tell me which package we must import to use the function lagrangePoly()?? Please
jd : Click on download zip at the right in the top of the page
How can i download this
very good code!
i have one question, why i got a big error of construction with the help of polynomial Lagrange?
hi, I am looking to interpolate the 3d interpolation but the problem is i am getting this input (x,y,z coordinates from a csv file which is not uniform and they do not follow a pattern).Can some one help me in this i can provide more details on this..please help me
Thank You. This work is excellent because is easy to understand is interesting how some people are worried to share the knowledge.
very good code, this can be used for analytical or numerical purposes, thanks a lot
nice work. appreciated
Well done. While I don't recommend the use of Lagrange polynomials unless you have a good reason for it, if you do, this code will serve you well. Dan has cleaned this code up very nicely.
This has some good points to it.
- A neatly published demo of its usage.
- Reasonable help, though somewhat lacking (see below.)
- Nicely written code that uses existing functionality quite well.
- Good internal comments to explain what is done.
What flaws did I see?
- No H1 line (so lookfor fails to find it.)
- At least one obvious bug (see below.)
- NO error checks. E.g., what if x or y are arrays? What about replicated elements in x?
- Mlint points out the unnecessary use of brackets.
- No references for the interested student.
- No "see also" references.
- It is Lagrange interpolation, for gods sake. This means the code has no real value except for educational purposes. Of the many such interpolants that have been posted, I'll concede this is probably the most cleanly written. I have not done any comparison for speed however.
What bug did I find? The help specifies only that x and y must be vectors. It works when they are ROW vectors.
>> [p,r,s]= lagrangepoly(rand(1,5),rand(1,5));
What happens for column vectors?
>> [p,r,s]= lagrangepoly(rand(5,1),rand(5,1));
??? Error using ==> mtimes
Inner matrix dimensions must agree.
Error in ==> lagrangepoly at 33
P = Y*pvals;
Finally, remember that Lagrange interpolation was a valuable tool for Lagrange, but he has been dead for almost 200 years. Since then, the world of applied mathematics has seen some very good advancements. Use a spline instead of Lagrange interpolation. There are many good variations.
As always, I am willing to revise my rating upwards if the problems are repaired.
Further improvements - more forgiving of input format (columns or rows), support the three-input form to behave like SPLINE, update documentation to refer to SPLINE (as a more modern version).
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.