next up previous contents
Next: PI Constant Pi Up: Base Constants Previous: NAN Not-a-Number Constant   Contents

Subsections

I-J Square Root of Negative One

Usage

Returns a complex value that represents the square root of -1. There are two functions that return the same value:

   y = i

and

   y = j.

This allows either i or j to be used as loop indices. The returned value is a 32-bit complex value.

Example

The following examples demonstrate a few calculations with i.

--> i
ans = 
  <complex>  - size: [1 1]
    0.00000000        1.0000000     i  
--> i^2
ans = 
  <complex>  - size: [1 1]
   -1.0000000         0.00000000    i

The same calculations with j:

--> j
ans = 
  <complex>  - size: [1 1]
    0.00000000        1.0000000     i  
--> j^2
ans = 
  <complex>  - size: [1 1]
   -1.0000000         0.00000000    i

Here is an example of how i can be used as a loop index and then recovered as the square root of -1.

--> accum = 0; for i=1:100; accum = accum + i; end; accum
ans = 
  <int32>  - size: [1 1]
          5050  
--> i
ans = 
  <int32>  - size: [1 1]
           100  
--> clear i
--> i
ans = 
  <complex>  - size: [1 1]
    0.00000000        1.0000000     i



Samit K. Basu 2005-03-16