Student Support Forum: 'Lagrange polynomial' topicStudent Support Forum > General > "Lagrange polynomial"

 < Previous Comment | Next Comment > Help | Reply To Comment | Reply To Topic
 Author Comment/Response Bill Simpson 11/20/12 7:03pm 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 http://mathworld.wolfram.com/LagrangeInterpolatingPolynomial.html 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. URL: ,

 Subject (listing for 'Lagrange polynomial') Author Date Posted Lagrange polynomial Mark Dymek 11/19/12 2:07pm Re: Lagrange polynomial Bill Simpson 11/20/12 7:03pm Re: Re: Lagrange polynomial Bill Simpson 11/21/12 00:10am Re: Lagrange polynomial [requested rewording] Mark Dymek 11/22/12 1:58pm
 < Previous Comment | Next Comment > Help | Reply To Comment | Reply To Topic