# Is it possible to write down matrix with variable row.

I wish to find out Moore Penrose psudo inverse of a matrix with variable row $4 \times k$ matrix with $k \in \mathbb{N}$ with entries a function of k. Is it possible to write down in SAGE?

edit retag close merge delete

Sort by » oldest newest most voted

Unless I'm misunderstanding your question (which is a bit ambiguous what does mean "with entries a function of k" ?), this should do :

sage: def myfunc(k): return floor(k*random())
sage: def make_4xk_matrix(k):
....:     return matrix(ZZ,[[myfunc(k) for t in (1..k)] for l in (1..4)])
....:
sage: make_4xk_matrix(6)
[1 5 3 3 4 3]
[5 2 3 3 2 3]
[2 3 1 3 3 3]
[0 2 3 2 1 5]


Note that the entries belong to $\mathbb{Z}$ : $\mathbb{N}$ is not a ring and Sage's matrix refuses it.

more

Then,

sage: L = [0, 4, 4, 1, 5, 1, 3, 1, 3, 2, 2, 1, 0, 5, 3, 3, 3, 2, 3, 3, 1, 0, 5, 2]
sage: M = matrix(4, L)
sage: M
[0 4 4 1 5 1]
[3 1 3 2 2 1]
[0 5 3 3 3 2]
[3 3 1 0 5 2]
sage: M.pseudoinverse()
[-15573/108749  18903/108749  -3411/108749  12744/108749]
[ -7882/108749 -13917/108749  19684/108749   6513/108749]
[ 22998/108749  18697/108749 -11848/108749 -19721/108749]
[-15071/108749  11925/108749  19094/108749  -7925/108749]
[ 15869/108749  -5687/108749 -12781/108749  10163/108749]
[-15989/108749  -2610/108749  13467/108749   9942/108749]

( 2018-01-20 16:00:40 +0200 )edit

Sebastien : and your question is ?

( 2018-01-20 17:33:32 +0200 )edit

I did not ask any question. I am just showing how the Moore Penrose Pseudo inverse can be obtained in Sage, which was the question.

( 2018-01-21 22:21:11 +0200 )edit