Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

As a programmer how would you explain imaginary numbers?

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

like image 529
Tim Matthews Avatar asked Feb 23 '09 07:02

Tim Matthews


People also ask

How do you explain imaginary numbers?

Imaginary numbers are the numbers when squared it gives the negative result. In other words, imaginary numbers are defined as the square root of the negative numbers where it does not have a definite value. It is mostly written in the form of real numbers multiplied by the imaginary unit called “i”.

How are imaginary numbers used in coding?

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

How do engineers use imaginary numbers?

Yes, electrical engineers use them as they are a mathematical representation of alternating current. They use 'j' to represent the square root of -1 (unlike mathematicians who use 'i') since in electrical engineering 'i' represents "current".

What are imaginary numbers actually used for?

Imaginary numbers, also called complex numbers, are used in real-life applications, such as electricity, as well as quadratic equations. In quadratic planes, imaginary numbers show up in equations that don't touch the x axis. Imaginary numbers become particularly useful in advanced calculus.


4 Answers

I guess this blog entry is one good explanation:

The key word is rotation (as opposed to direction for negative numbers, which are as stranger as imaginary number when you think of them: less than nothing ?)

alt text

Like negative numbers modeling flipping, imaginary numbers can model anything that rotates between two dimensions “X” and “Y”. Or anything with a cyclic, circular relationship

like image 87
VonC Avatar answered Oct 29 '22 02:10

VonC


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.

like image 25
Devin Jeanpierre Avatar answered Oct 29 '22 02:10

Devin Jeanpierre


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) = Acos(wt) + iB*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.

like image 9
Himadri Choudhury Avatar answered Oct 29 '22 01:10

Himadri Choudhury


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)

like image 2
sth Avatar answered Oct 29 '22 03:10

sth