Jump to content

Talk:Lagrange polynomial: Difference between revisions

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Content deleted Content added
Dila (talk | contribs)
No edit summary
Line 58: Line 58:
This avoid the cost of a test at each iteration. <small>—Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/199.212.17.130|199.212.17.130]] ([[User talk:199.212.17.130|talk]]) 14:44, 6 August 2008 (UTC)</small><!-- Template:UnsignedIP --> <!--Autosigned by SineBot-->
This avoid the cost of a test at each iteration. <small>—Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/199.212.17.130|199.212.17.130]] ([[User talk:199.212.17.130|talk]]) 14:44, 6 August 2008 (UTC)</small><!-- Template:UnsignedIP --> <!--Autosigned by SineBot-->


<code>
Do we really need this code? Does it contribute anything? I can't tell what it does without looking closely at it, since it has no explanation. I think it should be deleted. [[Special:Contributions/18.244.3.159|18.244.3.159]] ([[User talk:18.244.3.159|talk]]) 19:37, 23 April 2009 (UTC)

prod = 1;
for (int j=0; j<i; j++) {
prod *= (pos[i] - pos[j]);
weight *= (desiredPos - pos[j]);
}
for(int j=i+1; j<=degree; j++) {
prod *= (pos[i] - pos[j]);
weight *= (desiredPos - pos[j]);
}
weight /= prod;

</code>

This avoids the cost of a division each iteration. [[User:Dila|dila]] ([[User talk:Dila|talk]]) 08:09, 3 June 2009 (UTC)

Revision as of 08:09, 3 June 2009

I did a complete overhaul of the page. At the moment it is quite technical, maybe someone could add a practical example. MathMartin 16:58, 25 Apr 2004 (UTC)

Good work, sorry for all the errors, they were mine... Nixdorf 18:18, 25 Apr 2004 (UTC)
No sweat, I have not found any big errors. The article was just a bit small and blurry. I hope it is better now. Is there any reason you used t instead of x as a variable ? MathMartin 22:55, 25 Apr 2004 (UTC)
Not really, use x if you prefer. I come from physics so I like to think of it as "time", but generally, perhaps x is better. Nixdorf 16:33, 26 Apr 2004 (UTC)

Some one shoud add that can also be writen as

with

Multiplying by four

Do we really have to multiply everything by four, so that we get integers? It gave me something of a double-take. I think it would be more intuitive the other way, so it is easier to figure out what numbers came from where. Sim 16:29, 6 March 2007 (UTC)[reply]

I assume you're talking about using factors like in the construction of the Lagrange polynomial, instead of , in which case, I agree that it's better to do it the other way. Please go ahead and change it. -- Jitse Niesen (talk) 09:36, 7 March 2007 (UTC)[reply]


Errors

Any chance of a brief discussion of errors for Lagrange interpolation, preferably by someone who understands it properly (i.e., not me!)? me_and 21:21, 9 June 2007 (UTC)[reply]

Efficient code

instead of

     for (int j = 0; j < degree; ++j) {
        // The i-th term has to be skipped
        if (j != i) {
           weight *= (desiredPos - pos[j]) / (pos[i] - pos[j]);
        }
     }

it is more efficient to do two for loops


     for (int j=0; j<i; j++) {
        weight *= (desiredPos - pos[j]) / (pos[i] - pos[j]); 
     }

     for(int j=i+1; j<=degree; j++) {
        weight *= (desiredPos - pos[j]) / (pos[i] - pos[j]); 
     }

This avoid the cost of a test at each iteration. —Preceding unsigned comment added by 199.212.17.130 (talk) 14:44, 6 August 2008 (UTC)[reply]

     prod = 1;
     for (int j=0; j<i; j++) {
        prod *= (pos[i] - pos[j]);
        weight *= (desiredPos - pos[j]);
     }

     for(int j=i+1; j<=degree; j++) {
        prod *= (pos[i] - pos[j]);
        weight *= (desiredPos - pos[j]);
     }
     weight /= prod;

This avoids the cost of a division each iteration. dila (talk) 08:09, 3 June 2009 (UTC)[reply]