Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- typedef struct {
- double re, im;
- } Complex;
- int main(void) {
- Complex z;
- int retry = 1;
- do {
- --retry;
- Complex z0;
- printf("初期値のRe:"); scanf_s("%lf", &z0.re);
- printf("初期値のIm:"); scanf_s("%lf", &z0.im);
- int i = 0;
- double a = 0.00001;
- do {
- i++;
- z.re = z0.re;
- z.im = z0.re;
- double f_re = z0.re * z0.re - z0.im * z0.im + 5 * z0.re + 7;
- double f_im = 2 * z0.re * z0.im + 5 * z0.im;
- double df_re = 2 * z0.re + 5;
- double df_im = 2 * z0.im;
- double denom = df_re * df_re + df_im * df_im;
- z0.re = z0.re - (f_re * df_re + f_im * df_im) / denom;
- z0.im = z0.im - (- f_re * df_im + f_im * df_re) / denom;
- } while (fabs(z.re - z0.re) > a && fabs(z.im - z0.im) > a);
- z.re = z0.re;
- z.im = z0.im;
- printf("Re=%f , Im=%f, 回数は%d\n", z.re, z.im, i);
- puts("続けるなら0を");
- scanf_s("%d", &retry);
- } while (retry > 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement