Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: enumerating values for slopes

by BrowserUk (Patriarch)
on Sep 21, 2014 at 12:25 UTC ( [id://1101451]=note: print w/replies, xml ) Need Help??


in reply to enumerating values for slopes

So it is that I will have a math module for perl that will give me pi and degrees_to_radians at the end of this thread.

Take a look at Math::Trig. A well tested module that does all of that and much more.


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".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: enumerating values for slopes
by Aldebaran (Curate) on Sep 22, 2014 at 03:31 UTC
    $ perl slope3.pl Prototype mismatch: sub math1::pi () vs none at ../math1.pm line 13. Constant subroutine pi redefined at ../math1.pm line 7. Subroutine main::pi redefined at /usr/share/perl/5.18/Exporter.pm line + 66. at slope3.pl line 6. Prototype mismatch: sub main::pi: none vs () at /usr/share/perl/5.18/E +xporter.pm line 66. at slope3.pl line 6. slopes are 0 5 8 11 14 30 90 runs are 2.25 3.25 4 5 An angle of 0 degrees, or 0 radians, and run of 2.25 has a rise of 0 An angle of 0 degrees, or 0 radians, and run of 3.25 has a rise of 0 An angle of 0 degrees, or 0 radians, and run of 4 has a rise of 0 An angle of 0 degrees, or 0 radians, and run of 5 has a rise of 0 An angle of 5 degrees, or 0.0872664625997165 radians, and run of 2.25 +has a rise of 0.196849492933329 An angle of 5 degrees, or 0.0872664625997165 radians, and run of 3.25 +has a rise of 0.284338156459253 An angle of 5 degrees, or 0.0872664625997165 radians, and run of 4 has + a rise of 0.349954654103696 An angle of 5 degrees, or 0.0872664625997165 radians, and run of 5 has + a rise of 0.43744331762962 An angle of 8 degrees, or 0.139626340159546 radians, and run of 2.25 h +as a rise of 0.316216878080381 An angle of 8 degrees, or 0.139626340159546 radians, and run of 3.25 h +as a rise of 0.456757712782772 An angle of 8 degrees, or 0.139626340159546 radians, and run of 4 has +a rise of 0.562163338809566 An angle of 8 degrees, or 0.139626340159546 radians, and run of 5 has +a rise of 0.702704173511957 An angle of 11 degrees, or 0.191986217719376 radians, and run of 2.25 +has a rise of 0.437355695559867 An angle of 11 degrees, or 0.191986217719376 radians, and run of 3.25 +has a rise of 0.631736004697585 An angle of 11 degrees, or 0.191986217719376 radians, and run of 4 has + a rise of 0.777521236550874 An angle of 11 degrees, or 0.191986217719376 radians, and run of 5 has + a rise of 0.971901545688592 An angle of 14 degrees, or 0.244346095279206 radians, and run of 2.25 +has a rise of 0.560988006397157 An angle of 14 degrees, or 0.244346095279206 radians, and run of 3.25 +has a rise of 0.810316009240337 An angle of 14 degrees, or 0.244346095279206 radians, and run of 4 has + a rise of 0.997312011372723 An angle of 14 degrees, or 0.244346095279206 radians, and run of 5 has + a rise of 1.2466400142159 An angle of 30 degrees, or 0.523598775598299 radians, and run of 2.25 +has a rise of 1.29903810567666 An angle of 30 degrees, or 0.523598775598299 radians, and run of 3.25 +has a rise of 1.87638837486628 An angle of 30 degrees, or 0.523598775598299 radians, and run of 4 has + a rise of 2.3094010767585 An angle of 30 degrees, or 0.523598775598299 radians, and run of 5 has + a rise of 2.88675134594813 An angle of 90 degrees, or 1.5707963267949 radians, and run of 2.25 ha +s a rise of 3.67452885446896e+16 An angle of 90 degrees, or 1.5707963267949 radians, and run of 3.25 ha +s a rise of 5.3076527897885e+16 An angle of 90 degrees, or 1.5707963267949 radians, and run of 4 has a + rise of 6.53249574127815e+16 An angle of 90 degrees, or 1.5707963267949 radians, and run of 5 has a + rise of 8.16561967659768e+16 pi is 3.14159265358979 $ cat slope3.pl #!/usr/bin/perl -w use strict; use 5.010; BEGIN { push @INC, ".."; } use math1; use Math::Trig; my @slope = (0.0, 5.0, 8.0, 11.0, 14.0, 30.0, 90.0); say "slopes are @slope"; my @run = (2.25, 3.25, 4, 5); say "runs are @run"; foreach my $var1 (@slope) { my $s = degrees_to_radians($var1); foreach my $var2 (@run) { my $t = $var2 * tan($s); say "An angle of $var1 degrees, or $s radians, and run of $var2 has +a rise of $t"; } } my $a = pi(); say "pi is $a"; __END__ $

    I made this as quick and dirty as I had to to get results. I like the results partially, in that I believe they're correct. The aspiration to have my own module was admirable for its valor, but not with its merits. I figured out that what I was doing came within spitting distance of *literally* re-inventing the circle.

    $ cat math1.pm package math1; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( pi degrees_to_radians); sub pi{ use 5.010; use Math::Trig ':pi'; my $a = pi; return $a; } sub degrees_to_radians{ use 5.010; use Math::Trig qw(deg2rad); my $a = shift; my $b = deg2rad($a); return $b; } 1; $

    I'm still fishing for people's experience with this, but I'll post a cleaned-up version of this that relies on cpan properly, instead of wrapping the calls and confusing perl.exe. Thanks all for comments.

      Although it probably does not have any consequences here, I would suggest that you avoid using the $a (and $b) variable, because $a and $b are special purpose global variables used for sorting data (and a few other specific uses).
        $ perl slope5.pl Can't use string ("4.3125") as an ARRAY ref while "strict refs" in use + at ../utils1.pm line 39. $ cat slope5.pl #!/usr/bin/perl -w use strict; use 5.010; use Math::Trig; BEGIN { push @INC, ".."; } use utils1; my @AoA; my $aoa_ref = \@AoA; my @vector = (4.3125, 0.4375); push @AoA, @vector; @vector = (4.375, 0.375); push @AoA, @vector; @vector = (4.4375, 0.375); print_aoa($aoa_ref); __END__ $

        Thought I would be comparing hypotenuses to heights but can't see why perl doesn't this is ok.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-03-29 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found