int single_mandelbrot_point(complex_t coord_point, complex_t c_constant, int Max_iterations, double divergent_limit) { complex_t z_point; /* we need a point to use in our calculation */ int num_iterations; /* a counter to track the number of iterations done */ num_iterations = 0; /* zero our counter */ z_point = coord_point; /* initialize to the given start coordinate */ /* loop while the absolute value of the complex coordinate is < our limit (for a mandelbrot) or until we've done our specified maximum number of iterations (both julia and mandelbrot) */ while (absolute_complex(z_point) < divergent_limit && num_iterations < Max_iterations) { /* z = z*z + c */ z_point = multiply_complex(z_point,z_point); z_point = add_complex(z_point,c_constant); ++num_iterations; } /* done iterating for one point */ return num_iterations; }
int main(void){ Complex a, b, sum; printf("Enter a complex: "); scanf("%lf %lf", &a.real, &a.img); printf("Enter another complex: "); scanf("%lf %lf", &b.real, &b.img); sum = add_complex(a, b); printf("result = %g + %gi\n", sum.real, sum.img); return 0; }
//--------------------------------------------------------------------------------------------------- int main(){ complex c1 ={1.0,2.0,}; complex c2 = {2.0,3.0,}; complex c3 = add_complex(c1,c2); complex c4 = minus_complex(c1,c2); complex c5 = multiply_complex(c1,c2); complex c6 = div_complex(c1,c2); printf("c1 + c2 = (%f,%f)\n",c3.x,c3.y); printf("c1 - c2 = (%f,%f)\n",c4.x,c4.y); printf("c1 * c2 = (%f,%f)\n",c5.x,c5.y); printf("c1 / c2 = (%f,%f)\n",c6.x,c6.y); return 0; }
void fft_calc(const int N, const double *x, Complex *X, Complex *P, const int step, const Complex *twids){ int k; Complex *S = P + N/2; if (N == 1){ X[0].re = x[0]; X[0].im = 0; return; } fft_calc(N/2, x, S, X,2*step, twids); fft_calc(N/2, x+step, P, X,2*step, twids); for (k=0;k<N/2;k++){ P[k] = mult_complex(P[k],twids[k*step]); X[k] = add_complex(S[k],P[k]); X[k+N/2] = sub_complex(S[k],P[k]); } }
int main(void) { complex x, y, z, z2; /* 二つの複素数に値を代入 */ x.real = 3.0; x.imaginary = 2.0; y.real = 1.0; y.imaginary = -4.0; ShowComplex("s", x); ShowComplex("t", y); z = add_complex(x, y); /* 複素数の和を z に代入 */ ShowComplex("s + t", z); z2 = multiply_complex(x, z); /* 複素数の積を z に代入 */ ShowComplex("s(s + t)", z2); }