f



Table of tables

Given

t = {{{-1, -1, -2+2I}, {-1, -1, 3-I}}, {{-1, -1, 4+I}, {-1, -1, -5-5I}}};

how can I extract the imaginary part of the complex elements to obtain

{{{-1, -1, 2}, {-1, -1, -1}}, {{-1, -1, 1}, {-1, -1, -5}}};

thank you.

Luiz Melo


--


0
Luiz
10/20/2010 8:07:25 AM
comp.soft-sys.math.mathematica 28821 articles. 0 followers. Follow

5 Replies
1116 Views

Similar Articles

[PageSpeed] 39

On Oct 20, 1:07 am, Luiz Melo <luiz.m...@polymtl.ca> wrote:
> Given
>
> t = {{{-1, -1, -2+2I}, {-1, -1, 3-I}}, {{-1, -1, 4+I}, {-1, -1, -5-5I}}};
>
> how can I extract the imaginary part of the complex elements to obtain
>
> {{{-1, -1, 2}, {-1, -1, -1}}, {{-1, -1, 1}, {-1, -1, -5}}};
>
> thank you.
>
> Luiz Melo
>
> --

t /. u_Complex -> Im[u]

0
Ray
10/20/2010 9:45:55 AM
Hi Luiz!

Luiz Melo wrote:
> Given
> 
> t = {{{-1, -1, -2+2I}, {-1, -1, 3-I}}, {{-1, -1, 4+I}, {-1, -1, -5-5I}}};
> 
> how can I extract the imaginary part of the complex elements to obtain
> 
> {{{-1, -1, 2}, {-1, -1, -1}}, {{-1, -1, 1}, {-1, -1, -5}}};

What about:

Function[{e}, If[Im[e] == 0, e, Im[e]], Listable][t]

There seems to be no ComplexQ therefore I test with "Im[e] == 0" if it
is not a complex number.

Cheers,

Sebastian

0
Sebastian
10/21/2010 11:00:53 AM
Dear all!

Luiz was looking for a general solution how to act only on the third
component of his vectors. I came up with this:

t = {{{-1, -1, -2}, {-1, -1, -3}}, {{-1, -1, -4}, {-1, -1, -5}}};

Map[Apply[Function[{x, y, z}, {x, y, z + a}], #] &, t, {2}]

{{{-1, -1, -2 + a}, {-1, -1, -3 + a}}, {{-1, -1, -4 +
    a}, {-1, -1, -5 + a}}}

Here you see that I work only on the third component adding "a".

What do you think?

Cheers,

Sebastian

Luiz Melo wrote:
> Thanks Sebastian and Valeri for the help.
> 
> I'm actually looking for a function that operates only on the third row of each
> column-matrix terms(which happen to be complex in the example I gave), but
> leaves the other terms intact. Consider a different example:
> 
> Let
> t = {{{-1, -1, -2}, {-1, -1, -3}}, {{-1, -1, -4}, {-1, -1, -5}}};
> 
> how can I get
> 
> {{{-1, -1, 2}, {-1, -1, 3}}, {{-1, -1, 4}, {-1, -1, 5}}};
> 
> that is, in this case, I need a function that takes the Abs[] of the 3rd row of
> each sub-matrix and leaves the other terms intact.
> 
> Regards,
> Luiz
> 
> 
> 
>> Hi Luiz!
>>
>> Luiz Melo wrote:
>> > Given
>> >
>> > t = {{{-1, -1, -2+2I}, {-1, -1, 3-I}}, {{-1, -1, 4+I}, {-1, -1, -5-5I}}};
>> >
>> > how can I extract the imaginary part of the complex elements to obtain
>> >
>> > {{{-1, -1, 2}, {-1, -1, -1}}, {{-1, -1, 1}, {-1, -1, -5}}};
>>
>> What about:
>>
>> Function[{e}, If[Im[e] == 0, e, Im[e]], Listable][t]
>>
>> There seems to be no ComplexQ therefore I test with "Im[e] == 0" if it
>> is not a complex number.
>>
>> Cheers,
>>
>> Sebastian
>>
> 
> 
> --


0
Sebastian
10/21/2010 11:03:59 AM
t = {{{-1, -1, -2}, {-1, -1, -3}}, {{-1, -1, -4}, {-1, -1, -5}}};

t /. {x_, y_, z_?NumericQ} :> {x, y, Abs[z]}

{{{-1, -1, 2}, {-1, -1, 3}}, {{-1, -1, 4}, {-1, -1, 5}}}

or

Map[MapAt[Abs, #, -1] &, t, {2}]

{{{-1, -1, 2}, {-1, -1, 3}}, {{-1, -1, 4}, {-1, -1, 5}}}

% == %%

True


Bob Hanlon

---- Luiz Melo <luiz.melo@polymtl.ca> wrote: 

=============

Thanks Sebastian and Valeri for the help.

I'm actually looking for a function that operates only on the third row of each
column-matrix terms(which happen to be complex in the example I gave), but
leaves the other terms intact. Consider a different example:

Let
t = {{{-1, -1, -2}, {-1, -1, -3}}, {{-1, -1, -4}, {-1, -1, -5}}};

how can I get

{{{-1, -1, 2}, {-1, -1, 3}}, {{-1, -1, 4}, {-1, -1, 5}}};

that is, in this case, I need a function that takes the Abs[] of the 3rd row of
each sub-matrix and leaves the other terms intact.

Regards,
Luiz



> Hi Luiz!
>
> Luiz Melo wrote:
> > Given
> >
> > t = {{{-1, -1, -2+2I}, {-1, -1, 3-I}}, {{-1, -1, 4+I}, {-1, -1, -5-5I}}};
> >
> > how can I extract the imaginary part of the complex elements to obtain
> >
> > {{{-1, -1, 2}, {-1, -1, -1}}, {{-1, -1, 1}, {-1, -1, -5}}};
>
> What about:
>
> Function[{e}, If[Im[e] == 0, e, Im[e]], Listable][t]
>
> There seems to be no ComplexQ therefore I test with "Im[e] == 0" if it
> is not a complex number.
>
> Cheers,
>
> Sebastian
>

0
Bob
10/22/2010 5:37:16 AM
On Oct 21, 2010, at 7:01 AM, Luiz Melo wrote:

>
> Thanks Sebastian and Valeri for the help.
>
> I'm actually looking for a function that operates only on the third row of each
> column-matrix terms(which happen to be complex in the example I gave), but
> leaves the other terms intact. Consider a different example:
>
> Let
> t == {{{-1, -1, -2}, {-1, -1, -3}}, {{-1, -1, -4}, {-1, -1, -5}}};
>
> how can I get
>
> {{{-1, -1, 2}, {-1, -1, 3}}, {{-1, -1, 4}, {-1, -1, 5}}};
>
> that is, in this case, I need a function that takes the Abs[] of the 3rd row of
> each sub-matrix and leaves the other terms intact.

MapAt[Abs, t,
 Flatten[Table[{i, j, 3}, {i, First[Dimensions[t]]}, {j, Dimensions[t][[2]]}],
   1]]

More generally

mapAtColumn[t_,column_,f_]:==Module[{d},MapAt[f,t,Flatten[Table[Append[Table[d[i],{i,ArrayDepth[t]-1}],column],Evaluate[Sequence@@Table[{d[i], Dimensions[t][[i]]},{i,ArrayDepth[t]-1}]]],ArrayDepth[t-2]]]]

will map f onto the last position column of a multidimensional array t.  This can be further generalized to map onto a single value of a particular dimension and all other dimensional values.

Regards,
	Ssezi

>> Hi Luiz!
>>
>> Luiz Melo wrote:
>>> Given
>>>
>>> t == {{{-1, -1, -2+2I}, {-1, -1, 3-I}}, {{-1, -1, 4+I}, {-1, -1, -5-5I}}};
>>>
>>> how can I extract the imaginary part of the complex elements to obtain
>>>
>>> {{{-1, -1, 2}, {-1, -1, -1}}, {{-1, -1, 1}, {-1, -1, -5}}};
>>
>> What about:
>>
>> Function[{e}, If[Im[e] ==== 0, e, Im[e]], Listable][t]
>>
>> There seems to be no ComplexQ therefore I test with "Im[e] ==== 0" if it
>> is not a complex number.
>>
>> Cheers,
>>
>> Sebastian
>>
>
>
> --
>
>

0
Sseziwa
10/22/2010 5:38:33 AM
Reply: