Thread: sqrt (-1)

  1. #1
    Unregistered
    Guest

    Question sqrt (-1)

    I've recently took up an intrest in fractals. Now I would like to write a program so I can draw one, specifically the mandelbrot set. My problem is i don't know how to use imaginary numbers in C, i'm using Bordland C++ 3.0 but also have DJGPP. The equation for drawing the mandlebrot set is f(n) = f(n)^2 + C. Now my constant C = 1 + i and my first point, f(n), is 2+i.
    So f(n) = (2+i)^2 + 1 + i. I can do this out by hand, I get
    4 + 4i + i^2 + 1 + i which simplfies to 4 + 5i. I use that in my next iteration. I need to find out how to use imaginary numbers in C or where I can get a library so I can use them. Thanks for any help.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Start with
    Code:
    typedef struct {
        double real;
        double imaginary;
    } complex_t;
    Then write a few functions to add / multiply / sqrt

  3. #3
    Unregistered
    Guest
    I'm not the most advanced C programmer, could you give me an example on how to write a function where you preform a math function, doesn't matter which one really. Thanks For Any Help.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    http://www.google.com/search?q=mande...et+source+code

    Code:
    // from http://mathworld.wolfram.com/ComplexMultiplication.html
    complex_t c_mult ( complex_t a, complex_t b ) {
        complex_t result;
        result.real      = a.real * b.real - a.imaginary * b.imaginary;
        result.imaginary = a.real * b.imaginary + a.imaginary * b.real;
        return result;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2006, 04:37 PM
  2. sqrt() function help
    By willc0de4food in forum C Programming
    Replies: 5
    Last Post: 03-14-2005, 09:07 PM
  3. SQRT Mystery...
    By KneeLess in forum C Programming
    Replies: 7
    Last Post: 03-23-2004, 07:49 AM
  4. sqrt
    By modec in forum C Programming
    Replies: 3
    Last Post: 04-16-2003, 07:19 AM
  5. how sqrt ?
    By sambs1978 in forum C Programming
    Replies: 3
    Last Post: 09-20-2001, 08:14 AM