Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

lagrange interpolation

by spx2 (Deacon)
on Jul 17, 2007 at 18:06 UTC ( [id://627090]=perlquestion: print w/replies, xml ) Need Help??

spx2 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: lagrange interpolation
by jdporter (Paladin) on Jul 17, 2007 at 19:10 UTC

    I see two problems, and I have a feeling there are others.

    1. You're calling P_j with an argument of 4. This number is used as an index into @pair_points, which might not have any data at that index. With your sample data, for example, it doesn't.

    2. In the for loop, you give $generic_pol a value only conditionally (i.e. when $k != $j) but you always multiply $pol by it, regardless. Perhaps the for loop should be something like this:

    for( my $k = 0 ; $k < $n ; $k++ ) { next if $k == $j; my $generic_pol = Math::Polynomial->new( 1, -$pair_points[$k]- +>[0] ) / ( $pair_points[$j]->[0] - $pair_points[$k]-> +[0]); $pol *= $generic_pol; }
    A word spoken in Mind will reach its own level, in the objective world, by its own weight
      __
Re: lagrange interpolation
by shmem (Chancellor) on Jul 17, 2007 at 18:25 UTC
    it seems i'm failing

    How so? What are the errors? what did you expect, what was the outcome?

    i tried to debug

    How did you do that? What did you try?

    my patience has run out

    Neat idea: save a starved project with the patience of the Monastery Dwellers. That won't work (hopefully).

    have a go please and give me ideeas on how to make it do what it's supposed to do

    Care to provide any clues about "what it is supposed to do"?

    Your post is trollish, not in the sense of what's perceived as "Troll", but as in "trolling for baits". And you are not sharing your experience so far with your failed code, you are just throwing it in as a piece of raw flesh to the lions. We should work out, shouldn't we?

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://627090]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-24 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found