Parametrize iteration count for Newton's method

This commit is contained in:
Lucas 2020-03-08 22:33:18 +00:00
parent a6265017d1
commit 2b9b56737a
3 changed files with 16 additions and 11 deletions

16
julia.c
View file

@ -28,12 +28,14 @@
#include "fun.h"
#define OPTSTRING "a:b:c:D:d:h:Ll:N:n:w:x:y:z:"
struct color contour_color = { 0 };
static long double bailout = 1e100,
epsilon = 1e-8,
sec_w = 4.0,
contour = 0.0005L;
static long niters = 250;
static long niters = 250, newton_iters = 100;
static void
print_critical_points(void)
@ -103,7 +105,8 @@ usage(void)
fprintf(stderr, "Usage: %s julia [-L] [-x julia_x] [-y julia_y]\n"
" [-n niters] [-h height] [-w width] [-z zoom]\n"
" [-a center_x] [-b center_y] [-l light_intensity]\n"
" [-d density] [-c contour] [-D displacement]\n",
" [-d density] [-c contour] [-D displacement]\n"
" [-N newton_iters]\n",
xgetprogname());
exit(1);
}
@ -134,7 +137,7 @@ julia_main(int argc, char *argv[])
i, j;
int ch, do_light = 0;
while ((ch = getopt(argc, argv, "a:b:c:D:d:h:Ll:n:w:x:y:z:")) != -1)
while ((ch = getopt(argc, argv, OPTSTRING)) != -1)
switch (ch) {
case 'a':
cen_x = parse_double(optarg);
@ -160,6 +163,9 @@ julia_main(int argc, char *argv[])
case 'l':
light_intensity = parse_double(optarg);
break;
case 'N':
newton_iters = parse_integer(optarg, 1, LONG_MAX);
break;
case 'n':
niters = parse_integer(optarg, 1, LONG_MAX);
break;
@ -205,8 +211,8 @@ julia_main(int argc, char *argv[])
for (j = 0; j < width; j++) {
zx = cen_x + (j / (long double)width - 0.5L) * sec_w;
z = zx + I * zy;
if (behaves_critical(df, ddf, z, &crit, bailout,
epsilon))
if (behaves_critical(df, ddf, z, &crit, newton_iters,
bailout, epsilon))
add_critical_point(crit);
}
}