summaryrefslogtreecommitdiff
path: root/macros/cplxreal.sci
blob: 84438378dec6e6f3884439ef15bc7051372ecd10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function [zc, zr] = cplxreal (z, thresh)
//Function to divide vector z into complex and real elements, removing the one of each complex conjugate pair.
//Calling Sequence
//[zc, zr] = cplxreal (z, thresh)
//[zc, zr] = cplxreal (z)
//zc = cplxreal (z, thresh)
//zc = cplxreal (z)
//Parameters 
//z: vector of complex numbers.
//thresh: tolerance for comparisons.
//zc: vector containing the elements of z that have positive imaginary parts.
//zr: vector containing the elements of z that are real.
//Description
//This is an Octave function.
//Every complex element of z is expected to have a complex-conjugate elsewhere in z. From the pair of complex-conjugates, the one with the negative imaginary part is removed.
//If the magnitude of the imaginary part of an element is less than the thresh, it is declared as real.  
funcprot(0);
lhs = argn(1)
rhs = argn(2)
if (rhs < 1 | rhs > 2)
error("Wrong number of input arguments.")
end

select(rhs)
	case 1 then
		if(lhs==1)
		zc = callOctave("cplxreal",z)
		elseif (lhs==2)
		[zc, zr] = callOctave("cplxreal",z)
		else
		error("Wrong number of output argments.")
		end

	case 2 then
		if(lhs==1)
		zc = callOctave("cplxreal",z, thresh)
		elseif (lhs==2)
		[zc, zr] = callOctave("cplxreal",z, thresh)
		else
		error("Wrong number of output argments.")
		end
	end
endfunction