Perl: Converting Formula To Perl Code What Should It Look Like?

Viewed 86

I have the following formula:

Formula

I tried to convert this to perl code and it looks like this:

$stuck = (360 / $pi2);
$stuck2 = sin($stuck * $Eccent * $M);

Where $Eccent = 0.016713 and $M = 202.065469250756 and $pi2 = 3.1415927

I get -0.542630163200668

And the answer should be: -0.719461

Any help would be appreciated as I don't have a clue what it should look like!

1 Answers

The formula takes the sine of M, nothing else.

use Math::Trig qw( pi );

my $Ec = 360 / pi * $e * sin($M);

There's a catch: Your value of M is in degrees, while sin expects radians.

use Math::Trig qw( pi deg2rad );

my $Ec = 360 / pi * $e * sin(deg2rad($M));

This is equivalent to

use Math::Trig qw( deg2rad rad2deg );

my $Ec = rad2deg(2 * $e * sin(deg2rad($M)));
Related