Mathematica 9 is now available
Student Support Forum
Student Support Forum > General > > "Lagrange polynomial"

Post Reply:
Email Address:

Please send email when my message is replied to.

Url (optional):
Message: view original message?
Attachment (optional):
Please answer this:2+3 =

Original Message (ID '137897') By Bill Simpson:
Mathematica has never shown the steps to calculate a result, often even the algorithm used is undocumented. Sometimes you can write a simple calculation yourself and learn something in the process. From P(x) a Lagrange polynomial is a sum of product/product. If I haven't made any mistakes then this is one way of calculating that In[1]:= p[points_]:=Sum[Product[If[i==j,1,x-points[[i,1]]],{i,1,Length[points]}]/ Product[If[i==j,1,points[[i,1]]-points[[j,1]]],i,1,Length[points]}] *points[[j,2]], {j,1,Length[points]}]; poly=p[{{1,1},{2,4},{3,2}}] Out[2]= 1/2(-3+x)(-2+x)-4(-3+x)(-1+x)+(-2+x)(-1+x) In[3]:= {x,poly}/.{{x->1},{x->2},{x->3}} Out[3]= {{1,1},{2,4},{3,2}} And so the same input x values create the same output y values. You can also Expand that polynomial to get it into a more usual form if you like. Please check this carefully on different sets of data until you are fairly sure I didn't make any misatkes. You can also compare that definition of p with the example on the web page and try to understand how the two are related.