: operator

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 561
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

: operator

Message par compsystems » jeu. janv. 24, 2019 12:54 am

Hello

mat1 :=
[[ a, b ],
[ c, d ]]
mat1[:,1] => [b, d]

mat1[[:,1]] // This case is not recognized.
the output would be [a, c]

mat2 := [[ a, b, c ],[ d ]]
◉ size( mat2 ) [↵] returns 2
◉ dim( mat2 ) [↵] returns 2

for the DIM command, when the argument is not a matrix, please display a warning message

dim( mat2 ) [↵] returns 2
"/!\ the array is not a matrix"

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: : operator

Message par parisse » jeu. janv. 24, 2019 6:02 am

: is not an operator. It's implemented in Xcas for Python compatibility. Since Python does not provide indexes starting at 1, there is no reason to implement [[:,1]]. It's not that I don't want to do it, it's that each time I make a change in the parser, there is a high probability to introduce bugs.

compsystems
Messages : 561
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: : operator

Message par compsystems » dim. janv. 27, 2019 7:43 pm

I wanted to have compatibility with matlab =)


A: =
[[8,1,6],
[3,5,7],
[4,9,2]]

1: Index or extract the first row.
A[[1 ,:]] returns

[8,1,6]


2: Index or extract the first and second row.
A[[1..2 ,:]] returns

[[8,1,6],
[3,5,7]]


3: Index or extract the second and third column.
A[[:,2..3]] returns

[[1,6],
[5,7],
[9.2]]

4: Convert to column vector (matrix)
A[:] returns

[[8],
[1],
[6],
[3],
[5],
[7],
[4],
[9],
[2]]

5: Convert to row vector
A[..] returns

[8,1,6,3,5,7,4,9,2]

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: : operator

Message par parisse » lun. janv. 28, 2019 7:10 am

I don't know how matlab works. I don't think it's really important, matlab users have no reason to run Xcas.

Répondre