Alex Rivera | Logout

As a programmer how would you explain imaginary numbers?

Asked 2009-02-23T07:16:18.627
18

As a programmer I think it is my job to be good at math but I am having trouble getting my head round imaginary numbers. I have tried google and wikipedia with no luck so I am hoping a programmer can explain in to me, give me an example of a number squared that is <= 0, some example usage etc...

Edit
Report

2 Answers

2

Well, for the programmer:

class complex {
public:
  double real;
  double imaginary;

  complex(double a_real) : real(a_real), imaginary(0.0) { }
  complex(double a_real, double a_imaginary) : real(a_real), imaginary(a_imaginary) { }

  complex operator+(const complex &other) {
    return complex(
        real + other.real,
        imaginary + other.imaginary);
  }
  complex operator*(const complex &other) {
    return complex(
        real*other.real - imaginary*other.imaginary,
        real*other.imaginary + imaginary*other.real);
  }

  bool operator==(const complex &other) {
    return (real == other.real) && (imaginary == other.imaginary);
  }
};

That's basically all there is. Complex numbers are just pairs of real numbers, for which special overloads of +, * and == get defined. And these operations really just get defined like this. Then it turns out that these pairs of numbers with these operations fit in nicely with the rest of mathematics, so they get a special name.

They are not so much numbers like in "counting", but more like in "can be manipulated with +, -, *, ... and don't cause problems when mixed with 'conventional' numbers". They are important because they fill the holes left by real numbers, like that there's no number that has a square of -1. Now you have complex(0, 1) * complex(0, 1) == -1.0 which is a helpful notation, since you don't have to treat negative numbers specially anymore in these cases. (And, as it turns out, basically all other special cases are not needed anymore, when you use complex numbers)

answered 2009-02-23T08:27:54.087
0

Great answers so far (really like Devin's!)

One more point:

One of the first uses of complex numbers (although they were not called that way at the time) was as an intermediate step in solving equations of the 3rd degree. link

Again, this is purely an instrument that is used to answer real problems with real numbers having physical meaning.

answered 2009-02-23T08:02:13.273

Your Answer