# Can anyone confirm the Sqrt(-1)?

## Recommended Posts

Looking around at different sources of info regarding "Quarternions", I have noticed that they all dodge the question "What is the square root of -1?". The simply reply with "i". But what about the value returned from such an operation when put through a computer? Not much is documented... So, insted of being lazy, I tried it myself. Using C++, I wrote the following code... int square = sqrt(-1); printf( "Square Root = %d," square ); ...the output was... Square Root = 0 ...hmm. So I did the same, but using doubles insted of integers and got the following answer... Square Root = -1.#IND00 ...and so I got my -1. Yippie. But what the devil is the .#IND00 part of it? Have I made a mistake here, or something I simply don't understand? Any contributions are welcome.

##### Share on other sites
You get x.#IND00 becouse sqrt(-1) is not defined in real numbers. The i you got in book is part of imaginry number (one of imaginary components).

##### Share on other sites
i is the square root of -1, they're not dodging the issue.

It's defined as pow(i, 2) = -1.

You sound like you think that -1 is the square root of -1 : but pow(-1, 2) is 1.

There are many different number systems, but the one you want for dealing with i is called the complex numbers. You might want to have a look here.

Jim.

##### Share on other sites
You just cannot calculate the sqrt(-1) using integers or doubles. It doesn't exist in the domain of integers or real numbers! A computer cannot calculate it. A human couldn't either if he was restricted to the domain of reals, either.

##### Share on other sites
sqrt(-1) (where sqrt takes and returns float or double objects)is undefined in the same way 1/0 or 1%0 are undefined reals. What does that mean? That there is no commonly accepted value of these numbers: no value can be inferred from the rules that allow computation of a value in other cases, and no value is correct in all the cases where the operation might occur.

Theoretically, an exception should be thrown the same way an exception is thrown for 1/0 and 1%0, but instead sqrt uses return-value error detection, so you have to detect manually if the returned value is correct or not.

For complex numbers, you can define an sqrt() function that applies to anything, because x^2 - z always has one or two solutions in the complex plane, and you can order the complex numbers arbitrarily to choose the highest of the two values. In that case, sqrt(-1 + 0*I) == I. But this is not the case if you stick to real numbers (and their float/double computer-world equivalents).

##### Share on other sites
#include <complex>#include <iostream>using namespace std;int main(){  complex<float> c = -1;  cout << sqrt(c) << endl; }

Prints out (0,1) as expected. What exactly is your problem? [grin]

##### Share on other sites
The sqrt function knows not to even try negative numbers. If you use Newton's Method, which it most likely uses, then you repeatedly adjust a given function until it's answer is crossing the y axis. However, with negative values, it never nears the solution, and an infinite loop is created. try it with this, but take out the if at the top:

const double ACCURACY = 0.000001;double sq(double x){	if (x < 0) return ERRORCODE_NONREAL;	//start out with half x	double xn = x/2;	double diff = x - xn;	double tdiff;	double fx;	double fpx;	//loop while the difference between each iteration	//is greater than the accuracy value	while ( abs(diff) > ACCURACY )	{		//the function is x^2 - x		fx = xn * xn - x;		//the derivative is 2x		fpx = 2 * xn;		tdiff = xn;		//apply newtons method		xn = xn - fx / fpx;		diff = tdiff - xn;	}	return xn;}

##### Share on other sites
Back to the beginning: "-1.#IND" is a common printed representation for what the IEEE spec for floating point numbers calls a "quiet NaN", literally: quiet not a number. This is a non-signalling floating point value that represents the result of an invalid floating point operation, like taking the square root of -1.

##### Share on other sites
Re: JimPrice.

And so it would seem! o_0

That link you provided is indeed quite a find. I can't thank you enough. Cheers!

Re: Fruny.

MY PROBLEM!? YOU WANT TO KNOW MY "PROBLEM"?!?

My problem, my good Sir - is that I've been at this damn "problem" all day long since the crack of dawn! For some reason, I had decided to get of my arse and learn some Maths for a change! THAT is my problem!

I should have stayed in bed!

Oh, stop bawling - I'm just playing with you! In a Judge Judy kinda way...^_^

Seriously, your code still boggles my mind, but I start to get the idea that a complex number can be viewed in a component fashsion - similar to a vector. For that you get a cookie. You see - I'm not such a meanie, am I?

Re: The rest of you guys who replied!

This is more complex( no pun intended ) than I thought. Though I get the feeling that its simply one of those things that will click later as I go on learning.

One thing bothers me - is this concept considered to be a difficult concept in the world of Maths...or do I just plain suck?

Either way - thank you all for replying!

##### Share on other sites
Quote:
 Seriously, your code still boggles my mind, but I start to get the idea that a complex number can be viewed in a component fashsion - similar to a vector.

Bang on.

Quote:
 is this concept considered to be a difficult concept in the world of Maths...or do I just plain suck?

It's just something new to you - don't beat yourself up over it. You'll pick it up and in a short time you'll be replying to these types of threads yourself.

Oh yeah, and wait till you get to Quaternions...

Jim.

##### Share on other sites
Quote:
 Original post by JimPriceOh yeah, and wait till you get to Quaternions...

And just to let you know what you're in for with them, rumor has it they were invented by a drunk irishman as he was heading home from the pub (across a bridge, no less) [grin]

##### Share on other sites
Re: JimPrice.

Thanks for the encouraging words - it can feel like the world caving in around you when you can't understand something!

The funny thing, is - I can understand the Quarternion side of it, but its just this little piece of the puzzle that eludes me. Still, I shall keep at it. All tough nuts crack in the end!

Cheers.

##### Share on other sites
Re: Joanusdmentia.

No wonder this whole concept was considered baloney by mathematical authorities back its day!

##### Share on other sites
It gets even more fun when you get beyond quaternions to numbers that are not only non-abelian but also aren't associative.

##### Share on other sites
Re: Hyperspeed.

Quarternions is as far as I go! o_0

##### Share on other sites
After much sweat, blood and suger - I think I have not only quaternions, but the imaginary number sussed! I shall tell you my findings...

Just before dinner, I asked my father( he is really good at maths ) what the imaginary number is. He gave me a rather mystic idea - this what he said...

"Imagine I have this sphere in my hands and inside it is the square root of -1. With this value, I can now work out many other things about it, including the surface of this ball, the curve etc, etc..."

...I thought he was full of baloney just like the rest! I still didn't know what the square root of -1 was...grrrrr!

Get this - I was looking for a value. But it wasn't a value as such I was looking for...

I looked back at the form of a quaternion...

P = Pa + Pb*i + Pc*j + Pd*k

...in which I wondered how this was applied to our whole 3D pipeline. It goes something like this...

P = Pa + x*i + y*j + z*k

...so the x,y,z is pretty much our 3D values in question, and they are multiplied by their imaginary unit to make our "imaginary part", and those units are i,j,k( notice they resemble x,y,z ).

Now lets look at something else...

-4 = 4*-1

...and...

4 = 4*1

...and...

0 = 4*0

...I don't know about you - but I see a pattern here! Lets go back to our beloved quaternion and seperate "x*i" from the equation...

x*0 = 0

x*1 = x

x*-1 = -x

...and know let us look at an example identity matrix(its the only thing I can compare this to )...

1 0 0
0 1 0
0 0 1

...hmmm, interesting. And in a certain Tricks book, I found the author using this concept...

i = <1,0,0>
j = <0,1,0>
k = <0,0,1>

...At this stage, I'm a wolf that has caught my prey's scent. Lets try to unravel more of the puzzle( I'm hoping this is to the benefit of others stuggling with imaginary numbers! )...

i = <-1,0,0>
j = <0,-1,0>
k = <0,0,-1>

...AHA! So, if I make i = -1, I'm basically instructing the following...

P = Pa + x*-1 + y*j + z*k

...I think I am ready to spell it out now.

The imaginary number is an "instruction" more than it is a value. The value is simply what kind of instruction I want to have performed.

If I give the imaginary unit the value of 0, you will get...

x*0 = 0

...and as such, the value of 0 adds nothing to the final quaternion sum. In other words - "I do not want to perform an operation on x!". However...

x*1 = x

...I'm saying that I want x to be positive! And thus...

x*-1 = -x

...I would be saying that I want x to be negative. This whole thing also says that I want/don't want x to be included in the overall equation.

And thats it for now. I feel as thought I have caught on to the idea of what the use of an imaginary number is.

Over to you guys...

##### Share on other sites
You equate i with -1, that is simply wrong.

The idea is that i2 = -1.

This also applies to the quaternion components, although in those cases they are vectors and not scalars.

So

q = w + x * i + y * j + z * k

i2 = -1
j2 = -1
k2 = -1

i * j = - j * i = k
j * k = - k * j = i
k * i = - i * k = j

These basis vectors have these special properties which leads to the whole quaternion algebra and calculus.

This is an abstract definition and trying to find physical meaning just isn't important. The question 'what *is* i' is almost meaningless (your father obviously gets it) - it is a definition which allows for solviing a whole range of neat problems which we couldn't before.

For instance, try and solve:

x2 + 2 = 0

This is a perfectly reasonable quadratic equation, very easily stated but it cannot be solved without some value for sqrt(-1). You basically have two choices,

a) Just say that the equation is undefined (i.e. there is no value of x for which the equation holds)

b) Extend the number system you pick x from.

People wrestled with this for a long time before 'inventing' i to stand for sqrt(-1). Unfortunately to properly grok it you really need to have some experience in abstract algebra systems, where you'll see that everything is just definitions and asking 'what *really* is this' becomes meaningless at best (paradoxical at worst ;).

If you want some 'physical' meaning to attribute to these concepts, look at 'Geometric Algebra' which unifies quaternions and complex numbers (and a huge number of other things).

##### Share on other sites
Quote:
 Original post by JuNCIf you want some 'physical' meaning to attribute to these concepts, look at 'Geometric Algebra' which unifies quaternions and complex numbers (and a huge number of other things).

Physical meaning of imaginary numbers can easily be seen if you deal with AC voltage calculations (ok maybe that's more of a practical application[smile]).

Regards,
Pat.

##### Share on other sites
Re: Junc.

I'm now at the stage where I'm Gary Oldman from The Fifth Element - "HAHAHAHAHHAHAHAHAHAAAaaaamwmwmwmwmwmmw - they're not in here!"

Okay, you know how this is possible, but I see it in this way...the computer MUST have a value to work with. You simply cannot ask the computer x*i if i = ?. You cannot give it a "question mark".

##### Share on other sites
That value is i. i is as much a number as 5 or 12, it is just not real. Working with complex numbers, you have i DEFINED as root -1, in much the same way that when you learn numbers you have 1 DEFINED as being a singular quantity or the first counting number. i is just another number.

##### Share on other sites
Now that's simple - imaginary numbers are composed of two part - a real part and an imaginary one.
You can write them as x = a + bi or simply as a pair (a,b).
Programs working with imaginary numbers only need to apply the set of rules defined for them, e.g. i2=-1.

Now if you have something like z = x + y it boils down to z = (xa + ixb) + (ya + iyb) = (xa + ya) + i(xb*yb).
Since all components are real numbers, the computer can easily deal with them. If you use the pair notation you don't even 'see' the i from the imaginary part.

Hope this helps,
Pat.

##### Share on other sites
Re: AABBFFLLUUGG.

So I would be correct to assume that "i" is not a variable, but a value?

##### Share on other sites
Quote:
 Original post by AnriRe: AABBFFLLUUGG.So I would be correct to assume that "i" is not a variable, but a value?

Yes.

##### Share on other sites
Quote:
 Original post by AnriOkay, you know how this is possible, but I see it in this way...the computer MUST have a value to work with. You simply cannot ask the computer x*i if i = ?. You cannot give it a "question mark".

You're absolutely right, and they do. Imaginary number are numbers that are the sqrt of a negative value. Let's say you wnat the sqrt(-16). Now, this is exactly the same ax (-16)^0.5, so we can break this up into 2 parts, (16^0.5)*((-1)^0.5), or alternatively sqrt(16)*sqrt(-1) = 4i. Doing things this way we can represent any imaginary number as a real number (that the computer *can* work with) multiplied by i (which to the computer is totally meaningless).

Complex numbers include a 'normal' real number with this, so a complex number can be represented as x+yi. Now, while the computer can't do jack with 'i', it *can* do anything it pleases with x and y. The fact that the i is there means there are certain rules that need to be followed to make the mathematical operations valid. For example, multipication. Say you want to find (1+2i)*(3+4i), you just multiply them together as you would normally with an unknown variable, so you get (3+10i+8i^2). However, since we know that i=sqrt(-1) then i^2=-1. So really the result is (-5+10i), which is again in a form that the computer can represent using x and y.

Now when coding this multiplication on computer, we don't try and plug in a value for i, we just apply some simple rules that get us the same results. Say you have 2 complex number on the computer, (x1=1,y1=2) and (x2=3,y2=4). To multiply them together we would calculate x3=x1*x2-y1*y2, y3=x1*y2+x2*y1.

Also, another way to help visualise complex numbers is to consider real numbers as the x axis and imaginary numbers as the y axis. This also allows you to represent a complex number as a magnitude and an angle, which is sometimes very useful (for example, in AC electricity as mentioned earlier).

##### Share on other sites
Quote:
Original post by joanusdmentia
Quote:
 Original post by AnriOkay, you know how this is possible, but I see it in this way...the computer MUST have a value to work with. You simply cannot ask the computer x*i if i = ?. You cannot give it a "question mark".

You're absolutely right, and they do. Imaginary number are numbers that are the sqrt of a negative value. Let's say you wnat the sqrt(-16). Now, this is exactly the same ax (-16)^0.5, so we can break this up into 2 parts, (16^0.5)*((-1)^0.5), or alternatively sqrt(16)*sqrt(-1) = 4i. Doing things this way we can represent any imaginary number as a real number (that the computer *can* work with) multiplied by i (which to the computer is totally meaningless).

Complex numbers include a 'normal' real number with this, so a complex number can be represented as x+yi. Now, while the computer can't do jack with 'i', it *can* do anything it pleases with x and y. The fact that the i is there means there are certain rules that need to be followed to make the mathematical operations valid. For example, multipication. Say you want to find (1+2i)*(3+4i), you just multiply them together as you would normally with an unknown variable, so you get (3+10i+8i^2). However, since we know that i=sqrt(-1) then i^2=-1. So really the result is (-5+10i), which is again in a form that the computer can represent using x and y.

Now when coding this multiplication on computer, we don't try and plug in a value for i, we just apply some simple rules that get us the same results. Say you have 2 complex number on the computer, (x1=1,y1=2) and (x2=3,y2=4). To multiply them together we would calculate x3=x1*x2-y1*y2, y3=x1*y2+x2*y1.

Erhh, you just repeated what I already wrote (just using more words[smile]).

Regards,
Pat.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628327
• Total Posts
2982089

• 22
• 9
• 9
• 13
• 11