
Commerce: Financial Risk Management
CS 222
Project 2 – Array/String, Structure, Recursion, and Makefile
This project is to practice using array, structure, recursion, and multiple components compilation. It is an extension to the previous homework.
The Mandelbrot Set
The Mandelbrot set is a set of all complex numbers c that satisfy the following condition: the absolute value of mandelbrot(n) remains bounded when n (a natural number 0, 1, 2, …) tends to infinity, where
mandelbrot(n) = mandelbrot(n-1)*mandelbrot(n-1) + c;mandelbrot(0) = c.
Here the addition and multiplication are complex number addition and multiplication.
Specifically, for our project, if the absolute value of mandelbrot(15), |mandelbrot(15)|, is smaller than 10000 for a given c, then c is in the Mandelbrot set. If we consider a c as a 2D coordinates on a plane, the points in the rectangular area from lower-left corner (-2.0, -1.12) to upper-right corner (0.47, 1.12) will contain the Mandelbrot set. Our goal is to calculate a 2D array of points that covers the Mandelbrot set in this area and display the 2D array as an image. If a point is in the Mandelbrot set, we display a 1 (or #); otherwise, we display a 0 (or an empty space). You may save the area in a file so the area may contain many more points beyond your display. The number of points in the array, in other words, the number of row and columns, is up to you, but 40*30 will be sufficient to demonstrate the image.
Implementation details
1) You may use more files if you want, but here I recommend having complex.h, complex.c, Mandelbrot.h, Mandelbrot.c, Mandelbrot_print.h, Mandelbrot_print.c, main.c, and makefile. As always, you should write comments and implement the project a few statements at a time.
2) Constants, structure definitions, global variables, and function prototypes are defined in the header files for inclusions. Here in “complex.h”, you should have structure type definition for “complex_t” and function prototypes for “add_complex”, “multiply_complex”, and “abs_complex”.
3) In “complex.c”, you should include “complex.h”, so to have corresponding structure definition, and implementations of the functions. In general, related functions are grouped/implemented in the same c file. In “complex.c”, implement all the functions related to complex number operations as defined in the prototypes in the header file.
If you have system include files, they should be placed before the user defined header files. In general, never put a header file in another header file. They should be included explicitly.
4) mandelbrot.c implements the recursive function “complex_t mandelbrot(int n)”. In general, you should avoid using global variables, so the recursive function has to carry another input value, c, and mandelbrot(c, n) checks whether c belongs to the Mandelbrot set. In other words, your function should be mandelbrot(complex_t c, int n) 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).
mandelbrot(n) uses complex number addition and multiplication, so you should include “complex.h” in mandelbrot.c to allow mandelbrot(n) to access complex number functions. In the recursive function, |mandelbrot(n)| can be quite large beyond the computer’s representation. Therefore, in the recursion, if |mandelbrot(n-1)| is bigger than 10000, your recursion should consider that it is not bounded already, so you return mandelbrot(n) = (10000, 10000) instead of the calculated number to indicate that current c is not in the Mandelbrot set. Also, in the recursion, mandelbrot(n-1) is calculated twice, which is really wasting computing effort, so you should just calculate it once for efficiency.
5) In order for main.c to see the recursive function, you need to include “mandelbrot.h”. Because you use complex numbers in main.c, you need to include “complex.h” in main.c as well. Because mandelbrot function uses structure, so you should have “complex.h” included ahead of “mandelbrot.h”. Also, in order to print the generated image, you need to include “Mandelbrot_print.h”.
In main.c, for all point c in the area from (-2.0, -1.12) to (0.47, 1.12), we can check the corresponding mandelbrot(15) to see if it is in the Mandelbrot set. If it is in the set, which means that |mandelbrot(15)| is smaller than 10000, we save a ‘1’ in a 2D character array; otherwise, we save a ‘0’. At the end of each row, we save a NULL to make it a string. Therefore, we create an image of the Mandelbrot set saved in the 2D array. For example, you can check 40*30 points with a double for-loop in a rectangular area. That is, we start in x direction from -2.0 with step size (0.47-(-2))/40 = 0.06175 to 0.47, and in y direction from -1.12 with step size (1.12-(-1.12))/30 = 0.077 to 1.12. After that, we call Mandelbrot_print with the input of the 2D array pointer and the number of rows to print the image.
6) in Mandelbrot_print.c, you print the image by rows of strings. The function prototype is in Mandelbrot_print.h. If you want, as an option, which is not required for this project, you may save the image in a file, so you can check out a much larger image in the file with many more points. You can google images on Mandelbrot, and see the Mandelbrot set images with very fine points at the screen resolution with vivid colors.
7) In Makefile, the linking is usually the first rule in the Makefile. You need to link complex.o, Mandelbrot.o, Mandelbrot_print.o, and main.o into an executable called Mandelbrot. You should have rules that compile complex.c, Mandelbrot.c, Mandelbrot_print.c, and main.c into object files separately. Make sure the object files depend on the corresponding header files as well. In other words, for example, if you modify complex.h, complex.c, Mandelbrot.c, and main.c will be compiled again if you type “make”.
Testing and Submitting
Test your program on Mason to make sure that it compiles with “make” and runs properly. While on Mason, create a script file listing your programs to the screen in the following orders: Makefile, mandelbrot.h, mandelbrot.c, complex.h, complex.c, Mandelbrot_print.h, Mandelbrot.c, and main.c. Demonstrate a sample run with the Mandelbrot image. Submit all files (except the objects and the executable) to Blackboard.
‘>
Get professional assignment help cheaply
Are you busy and do not have time to handle your assignment? Are you scared that your paper will not make the grade? Do you have responsibilities that may hinder you from turning in your assignment on time? Are you tired and can barely handle your assignment? Are your grades inconsistent?
Whichever your reason may is, it is valid! You can get professional academic help from our service at affordable rates. We have a team of professional academic writers who can handle all your assignments.
Our essay writers are graduates with diplomas, bachelor, masters, Ph.D., and doctorate degrees in various subjects. The minimum requirement to be an essay writer with our essay writing service is to have a college diploma. When assigning your order, we match the paper subject with the area of specialization of the writer.
Why choose our academic writing service?
Plagiarism free papers
Timely delivery
Any deadline
Skilled, Experienced Native English Writers
Subject-relevant academic writer
Adherence to paper instructions
Ability to tackle bulk assignments
Reasonable prices
24/7 Customer Support
Get superb grades consistently
Get Professional Assignment Help Cheaply
Are you busy and do not have time to handle your assignment? Are you scared that your paper will not make the grade? Do you have responsibilities that may hinder you from turning in your assignment on time? Are you tired and can barely handle your assignment? Are your grades inconsistent?
Whichever your reason may is, it is valid! You can get professional academic help from our service at affordable rates. We have a team of professional academic writers who can handle all your assignments.
Our essay writers are graduates with diplomas, bachelor’s, masters, Ph.D., and doctorate degrees in various subjects. The minimum requirement to be an essay writer with our essay writing service is to have a college diploma. When assigning your order, we match the paper subject with the area of specialization of the writer.
Why Choose Our Academic Writing Service?
Plagiarism free papers
Timely delivery
Any deadline
Skilled, Experienced Native English Writers
Subject-relevant academic writer
Adherence to paper instructions
Ability to tackle bulk assignments
Reasonable prices
24/7 Customer Support
Get superb grades consistently
How It Works
1. Place an order
You fill all the paper instructions in the order form. Make sure you include all the helpful materials so that our academic writers can deliver the perfect paper. It will also help to eliminate unnecessary revisions.
2. Pay for the order
Proceed to pay for the paper so that it can be assigned to one of our expert academic writers. The paper subject is matched with the writer’s area of specialization.
3. Track the progress
You communicate with the writer and know about the progress of the paper. The client can ask the writer for drafts of the paper. The client can upload extra material and include additional instructions from the lecturer. Receive a paper.
4. Download the paper
The paper is sent to your email and uploaded to your personal account. You also get a plagiarism report attached to your paper.
PLACE THIS ORDER OR A SIMILAR ORDER WITH Essay fount TODAY AND GET AN AMAZING DISCOUNT
The post Financial Risk Management appeared first on Essay fount.
What Students Are Saying About Us
.......... Customer ID: 12*** | Rating: ⭐⭐⭐⭐⭐"Honestly, I was afraid to send my paper to you, but you proved you are a trustworthy service. My essay was done in less than a day, and I received a brilliant piece. I didn’t even believe it was my essay at first 🙂 Great job, thank you!"
.......... Customer ID: 11***| Rating: ⭐⭐⭐⭐⭐
"This company is the best there is. They saved me so many times, I cannot even keep count. Now I recommend it to all my friends, and none of them have complained about it. The writers here are excellent."
"Order a custom Paper on Similar Assignment at essayfount.com! No Plagiarism! Enjoy 20% Discount!"
