The Mandelbrot set is defined in the complex plane. It is the set of points C su
ID: 672584 • Letter: T
Question
The Mandelbrot set is defined in the complex plane. It is the set of points C such that the sequence Z(0) = C, Z(n + 1)=Z (n)*Z(n) + C is not divergent. It is clear that as soon as |Z(n) |>2 we are sure the sequence diverges. This is a programming exercise in which you have to use the complex number manipulating functions we will have written together in class a well as the pgm format black and white picture manipulating functions we will have reviewed in class to create your own representations of the Mandelbrot set. Write a C function mandelelem(...) that tests if a complex number C may still belong to the Mandelbrot set after a given maximal number of iterations. The maximal number of iterations should be provided as an argument to the function mandelelem() along with the complex number being tested. The function should return a 0 as soon as the divergence test is satisfied and it should return a 1 if the iteration limitation is reached without satisfying the divergence test. Calculations with complex numbers should be performed using the function we have written together and which are available in the file complex, cpp which will be downloadable from the webpage (Use #include "complex, cpp") Write a C program mandelbrot. cpp that creates a square pgm image with a number of pixels on one side of the square indicated in the 1st command line argument. Image operations should be performed using the functions in pgmtools. cpp downloadable from the webpage, so use #include "pgmtools. cpp" -sets the horizontal and vertical range of the picture according to the coordinates of the central point of the image whose real and imaginary parts are given as the second and third command line arguments while the horizontal and vertical range is set by the fourth command line arguments. -uses the function from to test all the points of the canvas. The maximal number of iteration should also be specified by the 5th and last command line argument. All grid points not passing the divergence test should be marked in black on the picture which you will save in a file named mandelbrot. pgm. Play with your program and explore the map of the Mandelbrot set. Once you have found a region you particularly like, modify your program in such a way your preferred parameters are used by default when no command line arguments are provided. Also, when no argument are provided, your program should print out instructions regarding the order in which arguments have to be provided to obtain a different picture. To submit your work, use the command: submit p6720 Lab04 mandelbrot.cppExplanation / Answer
(a)
#define mWidth 800;
#define mHeight 800;
class cNumber
{
private double a, b;
public cNumber(double realNumber, double imaginaryNumber)
{
a = realNumber; b = imaginaryNumber;
}
public double realPart()
{
return a;
}
public double imaginaryPart()
{
return b;
}
public double absoluteValue()
{
return (sqrt(exp(a,2)) + exp(b,2)));
}
}
checkMandelbrotElement(int N, cNumber c)
{
for (int i=N, cNumber z=0; i>=0; i--)
{
if (i == 0)
{
inTheSet(c);
} else if (z.absoluteValue() > 2)
{
notInTheSet(z);
break;
} else {
z = z^2 + c;
}
}
}
generateMandelbrot(cNumber c, int N) {
int pixels[i][j];
for (i=0; i<=mWidth; i++) {
for (j=0; j<=height, j++) {
cNumber z = new cNumber( ((i-400)/200), ((j-400)/200) );
checkMandelbrotElement(N, z, c);
}
}
(b)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream file("t.pgm");
const int width = 10;
const int height = 10;
const int max = 255;
file << "P2" << endl << width << " " << height << endl << max << endl;
for (int row=0; row<height; ++row)
{
for (int col=0; col<width; ++col)
{
file << 0 << " ";
}
file << endl;
}
cout << "This text will appear on the console" << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.