[fun-gen] add Nova fractal

This commit is contained in:
Lucas 2020-03-17 10:47:04 +00:00
parent f353cab392
commit 3da80b0552

View File

@ -196,7 +196,8 @@ usage(void)
fprintf(stderr, "Usage:\n" fprintf(stderr, "Usage:\n"
"\t%s p-degree q-degree p-coefs q-coefs\n" "\t%s p-degree q-degree p-coefs q-coefs\n"
"\t%s -h p-degree p-coefs\n" "\t%s -h p-degree p-coefs\n"
"\t%s -n p-degree p-coefs\n", p, p, p); "\t%s -N ra ia p-degree p-coefs\n"
"\t%s -n p-degree p-coefs\n", p, p, p, p);
exit(1); exit(1);
} }
@ -276,6 +277,43 @@ do_halley(int argc, char *argv[])
poly_free(&q); poly_free(&q);
} }
static void
do_nova(int argc, char *argv[])
{
struct poly f, df, p;
double complex a;
double ra, ia;
int i, j, f_degree;
if (argc < 3)
usage();
ra = parse_double(argv[0]);
ia = parse_double(argv[1]);
a = ra + I * ia;
argc -= 2; argv += 2;
f_degree = parse_integer(argv[0], 0, MAX_DEGREE);
if (argc != f_degree + 1 + 1)
usage();
poly_init(&f, f_degree, "f");
for (j = 0, i = 1 + f.degree;
i > 0;
i--, j++)
f.coefs[j] = parse_double(argv[i]);
poly_derivate(f, &df, "q");
poly_init(&p, f_degree, "p");
for (i = 0; i <= f.degree; i++)
p.coefs[i] = (i == 0 ? 0.0 : df.coefs[i - 1]) - a * f.coefs[i];
print_funs(p, df);
poly_free(&f);
poly_free(&df);
poly_free(&p);
}
static void static void
do_newton(int argc, char *argv[]) do_newton(int argc, char *argv[])
{ {
@ -309,14 +347,17 @@ do_newton(int argc, char *argv[])
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int ch, hflag, nflag; int ch, hflag, Nflag, nflag;
hflag = nflag = 0; hflag = Nflag = nflag = 0;
while ((ch = getopt(argc, argv, "hn")) != -1) while ((ch = getopt(argc, argv, "hNn")) != -1)
switch (ch) { switch (ch) {
case 'h': case 'h':
hflag = 1; hflag = 1;
break; break;
case 'N':
Nflag = 1;
break;
case 'n': case 'n':
nflag = 1; nflag = 1;
break; break;
@ -328,6 +369,8 @@ main(int argc, char *argv[])
if (hflag) if (hflag)
do_halley(argc, argv); do_halley(argc, argv);
else if (Nflag)
do_nova(argc, argv);
else if (nflag) else if (nflag)
do_newton(argc, argv); do_newton(argc, argv);
else else