Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

constructing a matrix from lists

asked 1 year ago

hamouda gravatar image

updated 1 year ago

Our goal is to build the 6×6 matrix whose rows are the coefficients of monomials z2,xy,y2,y3,y4,y5 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)Z[x,y,z] such that gk,i,j=xiyjfk 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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 1 year ago

Max Alekseyev gravatar image

updated 1 year ago

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)
Preview: (hide)
link

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: 1 year ago

Seen: 270 times

Last updated: Jun 17 '24