## How do I test a vector element by element for imaginary elements

### Asemahle Ndamase (view profile)

on 8 Apr 2019
Latest activity Commented on by Asemahle Ndamase

on 9 Apr 2019

### John D'Errico (view profile)

Here is the the vector i Have
r =
-1.6659 + 0.0000i
-0.3049 + 1.1564i
-0.3049 - 1.1564i
1.1378 + 0.3231i
1.1378 - 0.3231i
I am trying to check which elements are real numbers by means of a code, then after i'll have to calculate the percentage of those that are imaginary. Pls help
Thank You.

### John D'Errico (view profile)

on 8 Apr 2019
Edited by John D'Errico

### John D'Errico (view profile)

on 8 Apr 2019

What does the function imag return?
Given that, what would
imag( r ) ~= 0
tell you? see that it returns a true or false value for each element.
Now, how would you compute the fraction of imaginary elements? That seems simple, since you can write things like
sum(imag( r ) ~= 0)

Asemahle Ndamase

### Asemahle Ndamase (view profile)

on 9 Apr 2019
Thank You John, that solved my problem