J'ai mis à jour giacpy en version 0.6.1 sur Pypi.
Binaires windows + source pour les linuxiens qui ont la librairie giac et tout pour compiler.
Principale nouveauté: on peut affecter des vecteurs, matrices, listes... C'est une affectation sur place, probablement un peu plus lente que dans giac/xcas mais plus rapide que subsop.
NB: Pour les grandes matrices j'ai l'impression que A[0][0]=2 est plus rapide que A[0,0]=2.
j'ai ajouté aussi une partie Linear Algebra dans la doc de la fonction giac:
Code : Tout sélectionner
...
Linear Algebra:
---------------
* In Giac/Xcas vectors are just lists and matrices are lists of list.
>>> x,y=giac('x,y')
>>> A=giac([[1,2],[3,4]]) # we create a giac matrix from it lines
>>> v=giac([x,y]); v # a giac vector
[x,y]
>>> A*v # matrix product with a vector outputs a vector
[x+2*y,3*x+4*y]
>>> v*v # dot product
x*x+y*y
Remark that w=giac([[x],[y]]) is a matrix of 1 column and 2 rows. It is not a vector so w*w doesn't make sense.
>>> w=giac([[x],[y]])
>>> w.transpose()*w # this matrix product makes sense and output a 1x1 matrix.
matrix[[x*x+y*y]]
* In Python affectation doesn't create a new matrix. (cf. pointers) see also the doc of 'giacpy.Pygen.__setitem__'
>>> B1=A;
>>> B1[0,0]=43; B1 # in place affectation changes both B1 and A
[[43,2],[3,4]]
>>> A
[[43,2],[3,4]]
>>> A[0][0]=A[0][0]+1; A # similar as A[0,0]=A[0,0]+1
[[44,2],[3,4]]
>>> A.pcar(x) # compute the characteristic polynomial of A
x**2-48*x+170
>>> B2=A.copy() # use copy to create another object
>>> B2[0,0]=55; B2 # here A is not modified
[[55,2],[3,4]]
>>> A
[[44,2],[3,4]]
* Sparse Matrices are avaible via the table function.
>>> import giacpy
>>> A=giacpy.table(()); A # create an empty giac table
table(
)
>>> A[2,3]=33; A[0,2]='2/7' # set non zero entries of the sparse matrix
>>> A*A # basic matrix operation are supported with sparse matrices
table(
(0,3) = 66/7
)
>>> D=giacpy.diag([22,3,'1/7']); D # some diagonal matrix
[[22,0,0],[0,3,0],[0,0,1/7]]
>>> giacpy.table(D) # to create a sparse matrix from an ordinary one
table(
(0,0) = 22,
(1,1) = 3,
(2,2) = 1/7
)
But many matrix functions apply only with ordinary matrices so need conversions
>>> B1=A.matrix(); B1 # convert the sparse matrix to a matrix, but the size is minimal
[[0,0,2/7,0],[0,0,0,0],[0,0,0,33]]
>>> B2=B1.redim(4,4); B2.pmin(x) # so we may need to resize B1
x**3
...