I have two arrays, containing the real and imaginary parts of a list of complex numbers.
Re = {{Re_number1},{Re_number2},...}
Im = {Im_number1},{Im_number2},...}
I was wondering which is the smartest way to combine these two parts in a single array, containing complex numbers whose real and imaginary parts are taken from the two arrays Re
and Im
:
Complex = {{Re_number1 + i*Im_number1},...}
I guess there will be different ways to do that, maybe one thing to keep into account is that I will then need to make operations on these new complex numbers that I will create.
EDIT:
As @Belisarius suggested, I have tried with:
field [fullREAL_, fullIMAGINARY_] :=
Complex @@@ (Transpose@{fullREAL, fullIMAGINARY});
field[fullREAL, fullIMAGINARY] // MatrixForm
But it doesn't seem to work, although I suspect that's because I have made a syntax error...Can someone show me where? The arrays where I stored my rel and imaginary parts are created this way:
n = L = 8;
sigma = 3;
mu = 0.0;
leftREAL =
Table[{RandomVariate[
NormalDistribution[mu, Exp[-(2*Pi*k*sigma/L)^2]]]}, {k, n/2}];
rightREAL = Reverse[leftREAL] /. {x_, y_} -> {n - x, y};
fullREAL = Join[ {0.0}, Most[leftREAL], rightREAL] // MatrixForm
leftIMAGINARY =
Table[{RandomVariate[
NormalDistribution[mu, Exp[-(2*Pi*k*sigma/L)^2]]]}, {k, n/2 - 1}];
rightIMAGINARY = -Reverse[leftIMAGINARY] /. {x_, y_} -> {n - x, y};
fullIMAGINARY =
Join[ {0.0}, leftIMAGINARY, {0.0}, rightIMAGINARY] // MatrixForm
Complex @@@ (Transpose@{re, im})
$\endgroup$sigma
,L
andmu
. Remove the curly braces in the first arguments ofTable
and drop the postfix//MatrixForm
. belisarius' solution require you to havere={0,re1,re2,re3...}
while you havere=MatrixForm[{0,{re1},{re2},...,{ren}}]
. Similar consideration apply to imaginary parts. $\endgroup$n
,mu
, etc. Then you probably need to ditch theMatrixForm
. Pretty much you never use it in an assignment. It's for display purposes only. $\endgroup$