Parametrize iteration count for Newton's method
This commit is contained in:
parent
a6265017d1
commit
2b9b56737a
@ -17,18 +17,17 @@
|
|||||||
#include "criticals.h"
|
#include "criticals.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
size_t newton_iters = 100;
|
|
||||||
|
|
||||||
static size_t idx = 0;
|
static size_t idx = 0;
|
||||||
static long double complex criticals[100];
|
static long double complex criticals[100];
|
||||||
|
|
||||||
int
|
int
|
||||||
behaves_critical(long double complex (*df)(long double complex),
|
behaves_critical(long double complex (*df)(long double complex),
|
||||||
long double complex (*ddf)(long double complex), long double complex z,
|
long double complex (*ddf)(long double complex), long double complex z,
|
||||||
long double complex *crit, long double bailout, long double epsilon)
|
long double complex *crit, long niters, long double bailout,
|
||||||
|
long double epsilon)
|
||||||
{
|
{
|
||||||
size_t i;
|
long i;
|
||||||
for (i = 0; i < newton_iters && cabsl(z) < bailout; i++)
|
for (i = 0; i < niters && cabsl(z) < bailout; i++)
|
||||||
z = z - df(z) / ddf(z);
|
z = z - df(z) / ddf(z);
|
||||||
|
|
||||||
if (cabsl(df(z)) < epsilon) {
|
if (cabsl(df(z)) < epsilon) {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
int behaves_critical(long double complex (*)(long double complex),
|
int behaves_critical(long double complex (*)(long double complex),
|
||||||
long double complex (*)(long double complex), long double complex,
|
long double complex (*)(long double complex), long double complex,
|
||||||
long double complex *, long double, long double);
|
long double complex *, long, long double, long double);
|
||||||
void add_critical_point(long double complex);
|
void add_critical_point(long double complex);
|
||||||
size_t ncriticals(void);
|
size_t ncriticals(void);
|
||||||
long double complex get_critical(size_t);
|
long double complex get_critical(size_t);
|
||||||
|
16
julia.c
16
julia.c
@ -28,12 +28,14 @@
|
|||||||
|
|
||||||
#include "fun.h"
|
#include "fun.h"
|
||||||
|
|
||||||
|
#define OPTSTRING "a:b:c:D:d:h:Ll:N:n:w:x:y:z:"
|
||||||
|
|
||||||
struct color contour_color = { 0 };
|
struct color contour_color = { 0 };
|
||||||
static long double bailout = 1e100,
|
static long double bailout = 1e100,
|
||||||
epsilon = 1e-8,
|
epsilon = 1e-8,
|
||||||
sec_w = 4.0,
|
sec_w = 4.0,
|
||||||
contour = 0.0005L;
|
contour = 0.0005L;
|
||||||
static long niters = 250;
|
static long niters = 250, newton_iters = 100;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_critical_points(void)
|
print_critical_points(void)
|
||||||
@ -103,7 +105,8 @@ usage(void)
|
|||||||
fprintf(stderr, "Usage: %s julia [-L] [-x julia_x] [-y julia_y]\n"
|
fprintf(stderr, "Usage: %s julia [-L] [-x julia_x] [-y julia_y]\n"
|
||||||
" [-n niters] [-h height] [-w width] [-z zoom]\n"
|
" [-n niters] [-h height] [-w width] [-z zoom]\n"
|
||||||
" [-a center_x] [-b center_y] [-l light_intensity]\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());
|
xgetprogname());
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -134,7 +137,7 @@ julia_main(int argc, char *argv[])
|
|||||||
i, j;
|
i, j;
|
||||||
int ch, do_light = 0;
|
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) {
|
switch (ch) {
|
||||||
case 'a':
|
case 'a':
|
||||||
cen_x = parse_double(optarg);
|
cen_x = parse_double(optarg);
|
||||||
@ -160,6 +163,9 @@ julia_main(int argc, char *argv[])
|
|||||||
case 'l':
|
case 'l':
|
||||||
light_intensity = parse_double(optarg);
|
light_intensity = parse_double(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'N':
|
||||||
|
newton_iters = parse_integer(optarg, 1, LONG_MAX);
|
||||||
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
niters = parse_integer(optarg, 1, LONG_MAX);
|
niters = parse_integer(optarg, 1, LONG_MAX);
|
||||||
break;
|
break;
|
||||||
@ -205,8 +211,8 @@ julia_main(int argc, char *argv[])
|
|||||||
for (j = 0; j < width; j++) {
|
for (j = 0; j < width; j++) {
|
||||||
zx = cen_x + (j / (long double)width - 0.5L) * sec_w;
|
zx = cen_x + (j / (long double)width - 0.5L) * sec_w;
|
||||||
z = zx + I * zy;
|
z = zx + I * zy;
|
||||||
if (behaves_critical(df, ddf, z, &crit, bailout,
|
if (behaves_critical(df, ddf, z, &crit, newton_iters,
|
||||||
epsilon))
|
bailout, epsilon))
|
||||||
add_critical_point(crit);
|
add_critical_point(crit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user