Stata 11 help for mf_c

help mata C() -------------------------------------------------------------------------------

Title

[M-5] C() -- Make complex

Syntax

complex matrix C(numeric matrix A)

complex matrix C(real matrix R, real matrix I)

Description

C(A) returns A converted to complex. C(A) returns A if A is already complex. If A is real, C(A) returns A+0i -- A cast up to complex. Coding C(A) is thus how you ensure that the matrix is treated as complex.

C(R, I) returns the complex matrix R+Ii and is faster than the alternative R + I:*1i.

Remarks

Many of Mata's functions are overloaded, meaning they return a real when given real arguments and a complex when given complex arguments. Given real arguments, if the result cannot be expressed as a real, missing value is returned. Thus sqrt(-1) evaluates to missing, whereas sqrt(-1+0i) is 1i.

C() is the fast way to make arguments that might be real into complex. You can code

result = sqrt(C(x))

If x already is complex, C() does nothing; if x is real, C(x) returns the complex equivalent.

The two-argument version of C() is less frequently used. C(R, I) is literally equivalent to R :+ I*1i, meaning that R and I need only be c-conformable. For instance, C(1, (1,2,3)) evaluates to (1+1i, 1+2i, 1+3i).

Conformability

C(A): A: r x c result: r x c

C(R, I): R: r1 x c1 I: r2 x c2, R and I c-conformable result: max(r1,r2) x max(c1,c2)

Diagnostics

C(Z), if Z is complex, literally returns Z and not a copy of Z. This makes execution of C() applied to complex arguments instant.

In C(R, I), the i,j element of the result will be missing anywhere R[i,j] or I[i,j] is missing. For instance, C((1,3,.), (.,2,4)) results in (., 3+2i, .). If R[i,j] and I[i,j] are both missing, then the R[i,j] value will be used; e.g., C(.a, .b) results in .a.

Source code

Function is built in.

Also see

Manual: [M-5] C()

Help: [M-5] Re(); [M-4] scalar, [M-4] utility


© Copyright 1996–2009 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index