Polynomial derivative: Difference between revisions
Added Perl
m (added releated task) |
SqrtNegInf (talk | contribs) (Added Perl) |
||
Line 196:
Derivative of -x4-x3+x+1: 1 - 3*x^2 - 4*x^3
</pre>
=={{header|Perl}}==
<lang perl>use strict;
use warnings;
use feature 'say';
for ([5], [4,-3], [-1,3,-2,1], [-1,6,5], [1,1,0,-1,-1]) {
my @poly = @$_;
say 'Polynomial: ' . join ', ', @poly;
$poly[$_] *= $_ for 0 .. $#poly;
shift @poly;
say 'Derivative: ' . (@poly ? join', ', @poly : 0) . "\n";
}</lang>
{{out}}
<pre>Polynomial: 5
Derivative: 0
Polynomial: 4, -3
Derivative: -3
Polynomial: -1, 3, -2, 1
Derivative: 3, -4, 3
Polynomial: -1, 6, 5
Derivative: 6, 10
Polynomial: 1, 1, 0, -1, -1
Derivative: 1, 0, -3, -4</pre>
=={{header|Phix}}==
|