C에서 Mandelbrot 세트를 구현하려고하는데 이상한 문제가 있습니다. 다음과 같이 내 코드는 다음과 같습니다Mandelbrot 세트 코드에 어떤 문제가 있습니까?
#include <stdio.h>
#include <math.h>
#include <complex.h>
int iterate_pt(complex c);
int main() {
FILE *fp;
fp = fopen("mand.ppm", "w+");
double crmin = -.75;
double crmax = -.74;
double cimin = -.138;
double cimax = -.75; //Changing this value to -.127 fixed my problem.
int ncols = 256;
int nrows = 256;
int mand[ncols][nrows];
int x, y, color;
double complex c;
double dx = (crmax-crmin)/ncols;
double dy = (cimax-cimin)/nrows;
for (x = 0; x < ncols; x++){
for (y = 0; y < nrows; y++){
double complex imaginary = 0+1.0i;
c = crmin+(x*dx) + (cimin+(y*dy)) * imaginary;
mand[x][y] = iterate_pt(c);
}
}
printf("Printing ppm header.");
fprintf(fp, "P3\n");
fprintf(fp, "%d %d\n255\n\n", ncols, nrows);
for (x = 0; x < ncols; x++) {
for (y = 0; y < nrows; y++){
color = mand[x][y];
fprintf(fp, "%d\n", color);
fprintf(fp, "%d\n", color);
fprintf(fp, "%d\n\n", color); //Extra new line added, telling the ppm to go to next pixel.
}
}
fclose(fp);
return 0;
}
int iterate_pt(double complex c){
double complex z = 0+0.0i;
int iterations = 0;
int k;
for (k = 1; k <= 255; k++) {
z = z*z + c;
if (sqrt(z*conj(z)) > 50){
break;
}
else
++iterations;
}
return iterations;
}
그러나, PPM 파일로 저장이 프로그램의 출력은 다음과 같습니다 : 당신의 도움에 대한
감사합니다!
이 의사 코드에 대한 논리를 확인하십시오 : http://en.wikipedia.org/wiki/Mandelbrot_set#For_programmers – Blender
이 경우 관련성이 있지만 컴파일 할 때'경고 : 사용되지 않은 변수 '가 표시되는지 모르겠습니다. 당신의 코드. –
저는 실제와 허수를 나타내는 다른 기술을 실험하고 있었고이를 제거하는 것을 잊었습니다. –