Solved

fractals

Posted on 1998-05-06
7
179 Views
Last Modified: 2010-04-15
This is probably ridiculous...but; I need to know how to implement a complex (a.k.a. imaginary) formula type thing in order to generate the mandelbrot set. In fact I'm making this question worth 600 points (and possibly more) in order to have someone help me with this program I need to write for a grade. I'm not looking for someone to write the program for me because then I wouldn't learn anything but I do need alot of help.
For the mandelbrot set the rule is z->z*z+c.
C is the complex number. You may already know this but I should say it any ways.
So I guess to make a run down of this question is.....I need to know how to program complex numbers and then graph them. Could someone please help?
Thank you,
crash
0
Comment
Question by:crash020297
7 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
(a + b*i) + (c + d*i) = (a+c) + (b+d)*i

(a+b*i) * (c+d*i) =
(a*c) + (a*d*i) + (b*i * c) + (b*i * d*i) =
(a*c) + ((a*d)+(b*c))*i + (b*d)*(i*i) =
((a*c)-(b*d)) + ((a*d)+(b*c))*i

0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 600 total points
Comment Utility
To program them, use a struct that contains the real and imaginary part

eg.

typedef struct {
  double r;
  double i;
} Complex;

Now write functions for working with complex numbers.

eg.

Complex Add (Complex x, Complex y) {
  Complex z;
  z.r = x.r + y.r;
  z.i = x.i + y.i;
  return z;
}

The rules for complex arithmetic are fairly straighforward (I think that is what ozo was saying.

For graphing, use you graphics library and plot the real part as the x coord and imaginary as the y coord.  The details as to how to do this depends on what graphics library you have.

0
 
LVL 10

Expert Comment

by:RONSLOW
Comment Utility
For info on the Mandelbrot algorithm, look at

http://www.softlab.ece.ntua.gr/faq/fractal/faq-doc-6.html

You will need to be able to multiply two complex numbers (or at least square one) and to be able to add them, and be able to get the magnitude (||) of it to test for the exit condition.

The 'nice' way to do this is to write functinos for each operation.  More efficient is to expand out the calculations as one operation.  However, most compilers will be able to do optimizations (especially if the coplex functions are made static - in which case they will often be inlined).

Also, for efficiency, the operator may be better written as working on pointers.  eg

void AddIt (Complex* this, const Complex* that) {
  this->r += that->r;
  this->i += that->i;
}

This is quicker because 1) we are only passing pointers and not the whole complex struct. 2) we aren't constructing any temporary objects.

0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 10

Expert Comment

by:RONSLOW
Comment Utility
At the same site is a page with complex operations

http://www.softlab.ece.ntua.gr/faq/fractal/faq-doc-8.html

Here is (an excerpt) the text of that page .. You should be able to use these to write complex arithmetic functions

[NOTE: If you were able to use C++, then you could write a Complex class that understood operators like + etc, or just use the complex datatype from the standard library]

>>>
(note: a,b are reals, x,y are complex, i is the square root of -1)
Powers of i: i^2 = -1
Addition: (a+i*b)+(c+i*d) = (a+c)+i*(b+d)
Multiplication: (a+i*b)*(c+i*d) = a*c-b*d + i*(a*d+b*c)
Division: (a+i*b)/(c+i*d) = (a+i*b)*(c-i*d)/(c^2+d^2)
Exponentiation: exp(a+i*b) = exp(a)(cos(b)+i*sin(b))
Sine: sin(x) = (exp(i*x)-exp(-i*x))/(2*i)
Cosine: cos(x) = (exp(i*x)+exp(-i*x))/2
Magnitude: |a+i*b| = sqrt(a^2+b^2)
Log: log(a+i*b) = log(|a+i*b|)+i*arctan(b/a)
(Note: log is multivalued.)
Log (polar coordinates): log(r*e^(i*theta)) = log(r)+i*theta
Complex powers: x^y = exp(y*log(x))
DeMoivre's theorem: x^a = r^a * [cos(a*theta) + i * sin(a*theta)]

More details can be found in any complex analysis book.
>>>
0
 
LVL 10

Expert Comment

by:rbr
Comment Utility
Another good way is to use fractint. Fractint is distributed with the complete source code, so you can look in there and find good and fast algorithms for generating fractals.
0
 
LVL 10

Expert Comment

by:RONSLOW
Comment Utility
That might be cheating a bit .. and that program (along with many others) is referred to in the sites I suggested.

0
 

Author Comment

by:crash020297
Comment Utility
Thanks alot every one! This is so very helpful!
I really appreciate it.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now