views:

891

answers:

11

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...

A: 

WikiAnswers link

dirkgently
That link is rather defective. What justifies the use of a complex number over a simple two-dimensional vector space?
Devin Jeanpierre
The link works fine here.
tehvan
They can be interchanged. Is your question really, why should I use complex numbers instead of 2D vectors?
dirkgently
Yes, sorry. I just mean that the link says "we need two dimensions", but not "we need a square root for negative numbers", which is what complex numbers are all about.
Devin Jeanpierre
+19  A: 

Problem: not only am I a programmer, I am a mathematician. Solution: plow ahead anyway.

There's nothing really magical to complex numbers. The idea behind their inception is that there's something wrong with real numbers. If you've got an equation x^2 + 4, this is never zero, whereas x^2 - 2 is zero twice. So mathematicians got really angry and wanted there to always be zeroes with polynomials of degree at least one (wanted an "algebraically closed" field), and created some arbitrary number j such that j = sqrt(-1). All the rules sort of fall into place from there (though they are more accurately reorganized differently-- specifically, you formally can't actually say "hey this number is the square root of negative one"). If there's that number j, you can get multiples of j. And you can add real numbers to j, so then you've got complex numbers. The operations with complex numbers are similar to operations with binomials (deliberately so).

The real problem with complexes isn't in all this, but in the fact that you can't define a system whereby you can get the ordinary rules for less-than and greater-than. So really, you get to where you don't define it at all. It doesn't make sense in a two-dimensional space. So in all honesty, I can't actually answer "give me an exaple of a number squared that is <= 0", though "j" makes sense if you treat its square as a real number instead of a complex number.

As for uses, well, I personally used them most when working with fractals. The idea behind the mandelbrot fractal is that it's a way of graphing z = z^2 + c and its divergence along the real-imaginary axes.

Devin Jeanpierre
Do you mean 'x^2 + 4 = 0' at the top of this answer?
Gareth
Since when is it called j instead of i?
Rob Kennedy
For anyone wondering why this answer refers to 'j' but the other answers use 'i', both are used in different contexts - in my experience 'i' is used by mathematicians and 'j' is used by electrical engineers (presumably they already have an 'i' in use for something else)
Cebjyre
Eek, yes. I'll fix that right now.
Devin Jeanpierre
From http://en.wikipedia.org/wiki/I_(disambiguation) : 'I and i, symbols for electric current signals in electronic engineering' that'd be why they use 'j' then.
Cebjyre
I used j because that's used more often than i in the programming tools I use (for instance, 1 + 2j is a complex literal in Python, but 1 + 2i is not). The actual symbol doesn't matter in a mathematical context, so long as it's defined. By contrast, it does in a programming context.
Devin Jeanpierre
Much more precise than my answer. +1
VonC
+16  A: 
VonC
+1 for the great link!
dirkgently
I find that the rotation analogy doesn't make any sense; we don't need imaginary numbers for rotation: we have vectors.
hasen j
@hasen j: I don't follow. The two (vector and imaginary number) seems related, (wikipedia) "a 2-dimensional quantity can be represented mathematically as either a vector or as a complex number (known in the engineering context as phasor)". Imaginary numbers will be used to represent two dimensional variables **where both dimensions are physically significant**. A vector can do that (hence the "rotation part" of the answer), but "i" can be used in formula two represents 2 dimensions (like the static amplitude and phase information of a phasor).
VonC
my point is, the rotation/2d stuff seems to be merely a side effect. I think imaginary numbers are more intuitively explainable as a "hack" to solve an equation that doesn't have a solution for 0
hasen j
A: 

The main point is that you add numbers which you define to be solutions to quadratic equations like x2= -1. Name one solution to that equation i, the computation rules for i then follow from that equation.

This is similar to defining negative numbers as the solution of equations like 2 + x = 1 when you only knew positive numbers, or fractions as solutions to equations like 2x = 1 when you only knew integers.

starblue
A: 

It might be easiest to stop trying to understand how a number can be a square root of a negative number, and just carry on with the assumption that it is.

So (using the i as the square root of -1):

(3+5i)*(2-i)
= (3+5i)*2 + (3+5i)*(-i)
= 6 + 10i -3i - 5i * i
= 6 + (10 -3)*i - 5 * (-1)
= 6 + 7i + 5
= 11 + 7i

works according to the standard rules of maths (remembering that i squared equals -1 on line four).

Cebjyre
+6  A: 

You might also ask why do negative numbers exist? They exist because you want to represent solutions to certain equations like: x + 5 = 0. The same thing applies for imaginary numbers, you want to compactly represent solutions to equations of the form: x^2 + 1 = 0.

Here's one way I've seen them being used in practice. In EE you are often dealing with functions that are sine waves, or that can be decomposed into sine waves. (See for example Fourier Series).

Therefore, you will often see solutions to equations of the form:

f(t) = A*cos(wt)

Furthermore, often you want to represent functions that are shifted by some phase from this function. A 90 degree phase shift will give you a sin function.

g(t) = B*sin(wt)

You can get any arbitrary phase shift by combining these two functions (called inphase and quadrature components).

h(t) = A*cos(wt) + i*B*sin(wt)

The key here is that in a linear system: if f(t) and g(t) solve an equation, h(t) will also solve the same equation. So, now we have a generic solution to the equation h(t).

The nice thing about h(t) is that it can be written compactly as

h(t) = Cexp(wt+theta)

Using the fact that exp(iw) = cos(w)+i*sin(w).

There is really nothing extraordinarily deep about any of this. It is merely exploiting a mathematical identity to compactly represent a common solution to a wide variety of equations.

DasBoot
This is by far the simplest and the best explanation, I have ever seen.
Lakshman Prasad
A: 

An imaginary number is a real number multiplied by the imaginary unit i. i is defined as:

i == sqrt(-1)

So:

i * i == -1

Using this definition you can obtain the square root of a negative number like this:

   sqrt(-3)
== sqrt(3 * -1)
== sqrt(3 * i * i) // Replace '-1' with 'i squared'
== sqrt(3) * i     // Square root of 'i squared' is 'i' so move it out of sqrt()

And your final answer is the real number sqrt(3) multiplied by the imaginary unit i.

yjerem
A: 

A short answer: Real numbers are one-dimensional, imaginary numbers add a second dimension to the equation and some weird stuff happens if you multiply...

christian studer
A: 

If you're interested in finding a simple application and if you're familiar with matrices, it's sometimes useful to use complex numbers to transform a perfectly real matrice into a triangular one in the complex space, and it makes computation on it a bit easier.

The result is of course perfectly real.

poulejapon
A: 

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.

nimrodm
Complex numbers have physical meaning in quantum mechanics.
quant_dev
quant_dev: And that would be...?
Lakshman Prasad
+1  A: 

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)

sth