使用 C (DISLIN) 生成 Mandelbrot 集

Generating The Mandlebrot set with C (DISLIN)

我正在尝试使用 c 生成 mandlebrot 集,但得到了一些不正确的输出。 . .这段代码有什么问题?

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "dislin.h"

//generate jula set data for particular constant
static long double const_x;
static long double const_y;
static long double r_lim;

//handle complex number arithmetic
long double julia_x(long double x, long double y){
  return x * x - y * y;
}
long double julia_y(long double x, long double y){
  return 2 * x * y;
}

long double _abs(long double x, long double y){
  return sqrt(x * x + y * y);
}

//method for determining if a point in the plane is in the julia set
int julia_element(float x, float y, int max_steps){
  long double iter_x = (long double)x;
  long double iter_y = (long double)y;
  int i = 0;
  while(i < max_steps && _abs(iter_x, iter_y) < r_lim){
    long double x_temp = julia_x(iter_x, iter_y);
    iter_y = julia_y(iter_x, iter_y) + const_y;
    iter_x = julia_x(iter_x, iter_y) + const_x;
    i++;
  }
  return i;
}

int main(void){
  //constants for mandlebrot set
  const_x = -0.61803398875; //1 - golden ratio
  const_y = 0.0;
  long double radius = _abs(const_x, const_y);
  r_lim = 2; //solves r_lim(r_lim - 1) = radius

  static int julia_lim = 1000;

  //establish grid size and scale factor
  int POINTS = 10000;
  long double scale = 0.03;

  //store points to be plotted
  float * julia_set_x = malloc(POINTS * sizeof(float));
  float * julia_set_y = malloc(POINTS * sizeof(float));

  int current_x = 0;
  int count = 0;
  for(int i = 0; i < POINTS; i++){
    if(i % 100 == 0){
      current_x++;
    }

    float _x = (float)(-1.5 + current_x * scale);
    float _y = (float)(-1.5 + (i % 100) * scale);

    if(julia_element(_x, _y, julia_lim) == julia_lim){
      julia_set_x[i] = _x;
      julia_set_y[i] = _y;
      count++;
    }else{
      julia_set_x[i] = 0.0;
      julia_set_y[i] = 0.0;
    }
  }
  //draw julia set
  scrmod("revers");
  setpag("da4l");
  metafl("cons");
  disini();

  titlin("Julia Set", 1);
  titlin("F(Z) = Z*Z - 0.8 + 0.156i", 3);

  name("R-axis", "x");
  name("I-axis", "y");

  qplsca(julia_set_x, julia_set_y, 5 * count);


  free(julia_set_x);
  free(julia_set_y);
  return 0;
}

这是输出

只与此处的结果共享对称性:

https://en.wikipedia.org/wiki/Julia_set#/media/File:Time_escape_Julia_set_from_coordinate_(phi-2,_0).jpg

能得到一些想法会很棒

K

在 julia_element 这看起来不对:

long double x_temp = julia_x(iter_x, iter_y);
iter_y = julia_y(iter_x, iter_y) + const_y;
iter_x = julia_x(iter_x, iter_y) + const_x;

你是说

long double x_temp = julia_x(iter_x, iter_y);
iter_y = julia_y(iter_x, iter_y) + const_y;
iter_x = x_temp + const_x;

但为什么不使用 C 复数呢?