I am new to coding and am required to make a Mandelbrot function. For those of you who don't know, the Mandelbrot set is a set of complex numbers. Essentially, you take a complex number to start with, then square it and add it to the original complex number. For example, If I used the number 1, the set would be 0, 1, 2, 5, 26, ... I got this value from: 0, 1, (1^2) + 1 = 2, (2^2) + 1 = 5, (5^2) + 1 = 26. Now, my recursive function is supposed to find the sum of this set using two inputs: a number n, which is how far we are going into the set. For example, if n is 3, then my first example the set would be (0, 1, 2). The second input is a complex number structure, which I have already defined as two parts, an imaginary number and a real number. The goal is to multiply two complex numbers and add the original complex number. I have already made the multiply and add functions for complex as well, so essentially I just need help with the recursion part. Here is what I have so far:
#include <math.h>
#include <stdio.h>
complex_t mandelbrot(doublen, complex_t c) {
if(n == 0) {
return c;
}
else {
complex_t first = mandelbrot(n-1, c);
complex_t multiplied;
complex_t multiplied = multiply_complex(first, first);
return mandelbrot(n-1, multiplied);
}
For this program, n is going to be set to 15, and if the absolute value of the real part of the complex number is less than 100, it is in the mandelbrot set. However, this is done later; here, I just need to find out why my recursion process is not processing correctly.