Ask Your Question
0

constructing a matrix from lists

asked 2024-06-16 19:45:29 +0200

hamouda gravatar image

updated 2024-06-16 19:57:32 +0200

Our goal is to build the $6\times 6$ matrix whose rows are the coefficients of monomials ${z^2,xy,y^2,y^3,y^4,y^5}$ of the six polynomials $g_{(0, 0, 0)},g_{(0, 0, 1)},g_{(0, 0, 2)},g_{(0, 0, 3)},g_{(0, 0, 4)},g_{(0, 0, 5)}\in\mathbb{Z}[x,y,z]$ such that $g_{k,i,j}=x^iy^j f^k$ where $f=x+y+z$. My attempt in sage is to create a list $L$ defining the monomials and computing the six as rows lists as follows.

R.<x,y,z>=ZZ['x, y, z']
f=x+y+z
L=[(2, 0, 0),(0, 1, 1),(0, 0, 2),(0, 0, 3),(0, 0, 4),(0, 0, 5)]
for (k,i,j) in L:
               g=x^i*y^j*f^k
               L1=[g[x^i*y^j*z^k] for (k,i,j) in L]
               print(L1)

A naive solution, since sage outputs 6 rows $L1,L2,L3,L4,L5,L6$, the resulting matrix is

matrix([L1,L2,L3,L4,L5,L6])

But in practice I manipulate more than 100 polynomials, so I want to get a solution which outputs directly the matrix.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2024-06-17 03:13:12 +0200

Max Alekseyev gravatar image

updated 2024-06-17 03:14:47 +0200

You can grow your matrix row by row using method .stack():

R.<x,y,z>=ZZ['x, y, z']
f=x+y+z
L=[(2, 0, 0),(0, 1, 1),(0, 0, 2),(0, 0, 3),(0, 0, 4),(0, 0, 5)]
M = Matrix(0,len(L))
for (k,i,j) in L:
    g=x^i*y^j*f^k
    L1=vector(g[x^i*y^j*z^k] for (k,i,j) in L)
    M = M.stack(L1)
print(M)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-06-16 19:45:29 +0200

Seen: 161 times

Last updated: Jun 17