[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

fractals

Posted on 1998-05-06
7
Medium Priority
?
189 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 85

Expert Comment

by:ozo
ID: 1249644
(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 2400 total points
ID: 1249645
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
ID: 1249646
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:RONSLOW
ID: 1249647
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
ID: 1249648
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
ID: 1249649
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
ID: 1249650
Thanks alot every one! This is so very helpful!
I really appreciate it.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

831 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