|
|
|
|
|
by acqq
4838 days ago
|
|
Or even Perl: sub deriv { my $f = shift;
my $dx = 0.0001;
return sub { my $x = shift;
return ( &$f( $x + $dx ) - &$f( $x ) ) / $dx; }
}
sub cube { return $_[0] * $_[0] * $_[0]; }
print( deriv( \&cube )->( 2.0 ) );
12.0006000100226-------- "Lisp has all the visual appeal of oatmeal with fingernail clippings mixed in." -- Larry Wall (but see also http://www.perl.com/pub/2000/01/10PerlMyths.html#Perl_looks_...) |
|