Question: Real part of a matrix


----------------------------------------------------------------------------------------------------------------------
Introduction

I have a matrix (named DC on the piece of code below) all the elements of which are complex numbers a+b*I with a and b floating point numbers.
I want to obtain the real part of DC.

Obviously, if you do something like :
DC := Matrix(2,2, [1.0+1.0*I, 1.0-1.0*I, -1.0+1.0*I, -1.0-1.0*I];
Re~(DC);

the result corresponds to the desired matrix

----------------------------------------------------------------------------------------------------------------------
Context

In fact this matrix DC comes from some computations  described in the piece of code below

# Purpose :
# Given N points in a plane (here  in [0,1]X[0,1]), compute the matrix DX of distances between these points
#
# Example : if Pi and Pj are two such points, DX[i,j]=DX[j,i] denotes the Euclidian distance between Pi and Pj
#
# As I did not be able to find any single function in MAPLE that would construct DX , I proceed that way :
#   1/ let X the (N,2) matrix that contains the coordinates of the N points
#   2/ I represent these  N points as N complex numbers (vector C)
#   3/ I construct the (N,N) matrix MC = <C | C …..| C>
#   4/ I put MC = C – Transpose(C) :
#   5/ I take the norm DX of each elements of DC : DX := abs~(DC)
#       At this point, DX should contain the desired distances
#       But, due to floating point arithmetics, each element of DX writes a+0.*I where a is some floating point number)
#   6/ Last stage : execute Re~(DX)
#

with(Statistics):
with(LinearAlgebra):

N := 4:
X := Matrix(N,2, convert(Sample(Uniform(0,1), 2*N), list)):  #just an example

C   := X[..,1] +~ X[..,2] *~I;
MC := Multiply(C, Vector[row](N, 1));
DC := MC - Transpose(MC);
DX := abs~(DC);
Re~(DX)


----------------------------------------------------------------------------------------------------------------------
 My observations : 

1/ Maple 2015, Windows XP, 64 bytes
Re~(DX) returns DX and does not remove the imaginary (0.*I) part
But  Matrix(N, N, Re~(convert(DC, list))) does (which is a satisfactory, even if not clever, stopgap)

Why (it is just a question to help me to understand correctly how MAPLE proceeds) Re~(DC) does not (seem) to work here ?


2/ Maple 2015.2, Mac OS X El Capitan
DX := abs~(DC) gives me this strange result :
If (for instance) DC[i, j] = -1 – 2*I, DX[i, j] = +1 + 2*I
According to the compatibility problems between Maple 2015.1 and “El Capitan” (fixed from February), could it remain a few other problems ?

Last but not lesat : Did I do any syntax error ?


 I look forward to your responses

Please Wait...