Newton-Raphson fractals are captivating and visually stunning representations of complex polynomial equations.
Newton fractal for
Newton fractal for
In the syntax of this program, mathematical expressions involving complex numbers are made intuitive.
Complex z(1, 1);
Complex u = z * z * z // represends z^3
Complex w = Complex(12, 0) * z * z // represends 12 * z^2
Complex x = z*z*z*z - 1 // represends z^4 - 1
To create captivating Newton-Raphson fractal images with this program, follow these simple steps to get started:
- Define Your Polynomial: Open the main.cpp file within the project directory. Here, you can define your complex polynomial equation f(z) and its derivative df(z) inside the provided functions Complex f(Complex z) and Complex df(Complex z). Customize these functions with your own polynomial expressions as desired.
Complex f(Complex z) {
return z * z * z - 1; // Define your complex polynomial here (represends z^3 - 1)
}
Complex df(Complex z) {
return Complex(3, 0) * (z * z); // Define the derivative of your polynomial here (represends 3 * z^2)
}
-
Save Your Changes: Save the modifications you made to main.cpp.
-
Build the Program: Use the provided Makefile to build the program. Run the following command:
make all
- Generate the Fractal: Execute the program to generate the fractal image based on your custom polynomial equation:
./main
- Finished: The generated fractal image will be saved as fractal.ppm in the project directory.
To create captivating Newton-Raphson fractal images with this program, follow these simple steps to get started:
- Define Your Polynomial: Open the main.cpp file within the project directory. Here, you can define your complex polynomial equation f(z) and its derivative df(z) inside the provided functions Complex f(Complex z) and Complex df(Complex z). Customize these functions with your own polynomial expressions as desired.
Complex f(Complex z) {
return z * z * z - 1; // Define your complex polynomial here (represends z^3 - 1)
}
Complex df(Complex z) {
return Complex(3, 0) * (z * z); // Define the derivative of your polynomial here (represends 3 * z^2)
}
-
Save Your Changes: Save the modifications you made to main.cpp.
-
Build the Program: Here's the order of commands to compile the main program without using make, assuming you have the source files complex.cpp, complex.h and main.cpp:
g++ -c complex.cpp
g++ -c main.cpp
g++ complex.o main.o -o main
- Generate the Fractal: Execute the program to generate the fractal image based on your custom polynomial equation:
./main
- Finished: The generated fractal image will be saved as fractal.ppm in the project directory.
If you encounter an error message similar to the following:
User
g++ -c complex.cpp
cc main.o complex.o -o main
/usr/bin/ld: complex.o: in function `abs(Complex)':
complex.cpp:(.text+0x7a4): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
To resolve this issue, you need to link the math library explicitly when compiling your program. You can do this by adding the -lm flag to your compile command, like this:
g++ main.o complex.o -o main -lm