Ask Your Question
1

LU decomposition for symbolic matrices with many different variables.

asked 2022-06-19 09:35:28 +0100

lijr07 gravatar image

updated 2023-05-19 21:56:10 +0100

FrédéricC gravatar image

I asked a question about symbolic matrices and LU decompositions in https://ask.sagemath.org/question/628...

I have another question about LU decomposition. I would like to define a matrix $x_i(t)$ as a matrix with $1$'s on the diagonal and with $t$ at $(i,i+1)$ position, and all other entries are $0$. Let $g = x_{i_1}(t_1) \cdots x_{i_m}(t_m) T$, where $i_1, \ldots, i_m$ are some given integers, $T$ is a diagonal matrix with entries $\lambda_1, \ldots, \lambda_n$. I would like to define this matrix in Sage and apply LU decomposition to it. Now $t_1, \ldots, t_m, \lambda_1, \ldots, \lambda_n$ are symbols. How to do this in Sage? Thank you very much.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2022-06-19 13:41:21 +0100

tmonteil gravatar image

updated 2022-06-19 13:47:29 +0100

First, let me suggest that all your indices start at 0, not 1. This might look weird at the beginning, but you will see that it is very convenient in the longer term.

You can define your inteterminates as follows:

sage: m,n = 6,10
sage: R = PolynomialRing(QQ,names=['t{}'.format(i) for i in range(m)] + ['lambda{}'.format(i) for i in range(n)]).fraction_field()
sage: R
Fraction Field of Multivariate Polynomial Ring in t0, t1, t2, t3, t4, t5, lambda0, lambda1, lambda2, lambda3, lambda4, lambda5, lambda6, lambda7, lambda8, lambda9 over Rational Field
sage: R.gens()
(t0,
 t1,
 t2,
 t3,
 t4,
 t5,
 lambda0,
 lambda1,
 lambda2,
 lambda3,
 lambda4,
 lambda5,
 lambda6,
 lambda7,
 lambda8,
 lambda9)

To access the inteterminates easily, you can do:

sage: t = R.gens()[:m]
sage: l = R.gens()[m:]

You can check:

sage: t[1] + l[3]
t1 + lambda3

If you want nice LaTeX rendering in jupyter notebook, you can do:

%display latex

You can define the matrix $x_i(t)$ as follows:

sage: def x(i,t):
....:     m = matrix.identity(R,n)
....:     m[i,i+1] = t
....:     return m

You can check, e.g.

sage: x(1,t[3])

The matrix $T$ can be easily defined:

sage: T = matrix.diagonal(l)

Now, if L is the list of indices $i_0,\dots,i_{m-1}$, you can define the matrix $g$ as follows:

sage: def g(L):
....:     M = matrix.identity(R,n)
....:     for i,l in enumerate(L):
....:         M = M * x(l,t[i])
....:     return M * T

You can check for example:

sage: g([0,1,3,5,6,8])
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: 2022-06-19 09:35:28 +0100

Seen: 274 times

Last updated: Jun 19 '22