Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Lagrange Polynomials in Perl

by BrowserUk (Patriarch)
on Apr 28, 2015 at 19:51 UTC ( [id://1125059]=note: print w/replies, xml ) Need Help??


in reply to Lagrange Polynomials in Perl

You cannot shift an array off the argument stack: my @x = shift;

Assuming you are calling this as: lagrange( \@vals, \@funcs );

What you are shifting of the argument stack is an array reference; and to do that properly you need to assign it to a scalar variable:

my $refX = shift;

And then indirect through that to get your values:

$den *= ( $refX->[$i] - $refX->[$j] );

Do that for both your parameter arrays -- athough you do not seem to ever use @f anywhere in that function?

Also, what do you think this does:      my $point = @x;?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re^2: Lagrange Polynomials in Perl
by Mascasc (Novice) on Apr 28, 2015 at 19:56 UTC
    Does $scalar = @array produce a scalar containing the size of the array?
      Does $scalar = @array produce a scalar containing the size of the array?

      Yes. But $point is a strange name for the size of an array!

      If that is meant to be short for $lastPoint, it is still deceptive as with zero-based arrays, the index of the last point in the array is one less than the size of the array.

      (Which incidentally, can be obtained using my $lastPoint = $#array;)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
      In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
        Yeah, I was thinking of it as the stopping point for the for loop more than the last point, although you are right...it's pretty unclear.
      Yes, it does, but I would rather write:
      my $array_count = scalar @array;
      or, omitting the scalar built-in unnecessary in scalar context:
      my $array_count = @array;
      But I often prefer to add the scalar built-in, even when not necessary, just to make my intent clearer to the maintainer (which, incidentally, one year from now, might be me, and such indication might prove useful to help me understand the intent of the code).

      Update: removed the scalar word which I had forgotten to omit in the second snippet. Thanks to Athanasius for pointing it out.

      Je suis Charlie.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-25 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found