QuestionQuestion

The Mandelbrot set is the set of all complex numbers c for which sequence defined by the recursive function
mandelbrot(n) = mandelbrot(n-1)*mandelbrot(n-1) + c; f(0) = c
remains bounded or converges to a fixed number when n tends to infinity. Here the addition and multiplication are complex number addition and multiplication.

Specifically, if the absolute value of mandelbrot(15) < 100 for a given c, then c is in the Mandelbrot set. If we consider a 2D coordinates on a plane, the points in the area from (-2.0, -1.1) to (0.45, 1.1) will contain the Mandelbrot set.

Our goal is to calculate an array of points that covers the Mandelbrot set and display the array with an image on the screen.

Implementation

Include a file mandelbrot.c, which implement the recursive function mandelbrot(n). In the recursive function, the (x, y) values can be quite large beyond the computer’s representation. Therefore, in the function, if |mandelbrot(n-1)| is bigger than 1000, your recursion should consider that it is not bounded, so you return mandelbrot(n) = (1000, 1000) instead of the calculated number.

Third, in order for main.c to see the recursive function, you need another file mandelbrot.h to help. The final executable is called mandelbrot. Make sure your Makefile will compile the three object files, and link them together.

As I have said, you should avoid using global variables always, so the recursive function has to carry another input value, c, and mandelbrot(n) checks whether c belongs to the Mandelbrot set. In other words, your function should be mandelbrot(n, c) instead. Optionally, for the purpose of learning, you may define a global variable c in main.c, and use “extern” in mandelbrot.h to make it visible in mandelbrot.c, so you can just use mandelbrot(n).

Finally, in main.c, for all point c starting from (-2.1, -1.2) with 0.032 increment step along x and 0.05 increment step along y, check the corresponding mandelbrot(15, c). You are supposed to check 80*45 points and display them as an image. (You are allowed to use a different step along x or y and check different area of points, but the final result has to be all visible on the default display.) When |mandelbrot(15, c)| is bigger than 100, you should consider it is not bounded, so you display an empty space or “-“. Otherwise, you display a “#” as a point in the Mandelbrot set. If you want, you may save the image in a two dimensional array of characters first and then print out the image.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <stdlib.h>

#include "mandelbrot.h"

complex_t mandelbrot(int n, complex_t c){
    /*based case*/
    if (n == 0) {
       return c;
    }
    /* get mandelbrot(n - 1) */
    complex_t t = mandelbrot(n - 1, c);
    /* get |mandelbrot(n - 1)| */
    complex_t ab = abs_complex(t) ;
    /* return new value if it is out of bound */
    if (ab.real > 1000.0) {
       t.real = 1000.0;
       t.imag = 1000.0;         
       return t;
    }...
$50.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats