Solved

fractals

Posted on 1998-05-06
7
182 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
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 600 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
port mapped I/o query 10 184
Why this code doesn't work? 8 99
Problem with MFCApp 78 380
chcp 65001 File encoding 66 246
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

785 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