aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2022-01-03 19:54:47 -0600
committerLuis Mochan <mochan@fis.unam.mx>2022-01-03 19:54:47 -0600
commit3a59f18ae190727e4c330bd78db48ddad6222931 (patch)
treee9fcc9b7cf40d9d2c83a174c6fbaad60efe9f39c
parent7254005f3f3ee7b2885413f367e9f4cff214bf9c (diff)
downloadperlweeklychallenge-club-3a59f18ae190727e4c330bd78db48ddad6222931.tar.gz
perlweeklychallenge-club-3a59f18ae190727e4c330bd78db48ddad6222931.tar.bz2
perlweeklychallenge-club-3a59f18ae190727e4c330bd78db48ddad6222931.zip
Add a more informative error message
-rwxr-xr-xchallenge-146/wlmb/perl/ch-1.pl5
1 files changed, 3 insertions, 2 deletions
diff --git a/challenge-146/wlmb/perl/ch-1.pl b/challenge-146/wlmb/perl/ch-1.pl
index 317809535d..d468503b4a 100755
--- a/challenge-146/wlmb/perl/ch-1.pl
+++ b/challenge-146/wlmb/perl/ch-1.pl
@@ -28,10 +28,11 @@ for my $N(@ARGV?@ARGV:10001){
no PDL::NiceSlice; # NiceSlice destroys indirect function calls!
sub find_zero { # Find zero of function using Newton's iteration
- my ($f, $d, $x)=@_; # function, derivative, initial guess
+ my ($f, $d, $x0)=@_; # function, derivative, initial guess
+ my $x=$x0;
my $y;
my $max=10; # guard against non-convergence
do{($y, $x)= ($x, $x-$f->($x)/$d->($x))} until approx($y,$x) or --$max<=0;
- die "find_zero didn't converge" unless $max>0;
+ die "find_zero didn't converge starting from $x0\n" unless $max>0;
return $x;
}