Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sympy: Singular Value Decomposition of Symbolic Matrix

I am trying to solve what I thought was a simple problem. I seek the non-trivial solution to Ax = b, where b is the zero vector and A is a known matrix of symbolic elements (non-singular). Matlab does not permit non-numerical inputs to its svd function so I installed the sympy module and have tried the following code to solve my problem.

from numpy import *
from sympy import *
import sympy.matrices.matrices

a2, a3, k2_prime, rho2, rho2_prime_prime = symbols('a2 a3 k2_prime rho2 rho2_prime_prime', real=True)

A = Matrix([[exp(rho2*a2) , -exp(1j*k2_prime*a2), -exp(-1j*k2_prime*a2)  , 0],
[rho2*exp(rho2*a2), -1j*k2_prime*exp(1j*k2_prime*a2), -1j*k2_prime*exp(-1j*k2_prime*a2), 0],
[0, exp(1j*k2_prime*a3), exp(-1j*k2_prime*a3), exp(-rho2_prime_prime*a3)],
[0, 1j*k2_prime*exp(1j*k2_prime*a3), -1j*k2_prime*exp(-1j*k2_prime*a3), -rho2_prime_prime*exp(-rho2_prime_prime*a3)]])


g = MatrixBase.singular_values(A)

print g

The result is a null matrix, which clearly isn't correct. Does anyone know what I'm doing wrong? Is there a better way to go about this?

like image 443
Trevor Avatar asked Nov 20 '25 18:11

Trevor


1 Answers

It seems it is more a mathematical incomprehension rather than a programming issue. Here, is a simple argument to understand why sympy is right, assuming A is invertible.

In fact, if a square matrix A is non-singular, then a linear system Ax = b, has a unique solution x, because it is a bijective map. Now, in your case b ≡ 0 (meaning every coefficient is null), then the vector x ≡ 0 is satisfying the system. Then, since the solution is unique, it is the only solution. ∎

NB: What you are describing is called a system inversion (it is not necessary to compute the SVD), which can be abruptly done either by multiplying b at its left by A-1 or by other algorithms like QR and LU decompositions, etc. And, in the specific case where b ≡ 0; it is called the kernel of the matrix (set of the zeros of a function).

like image 98
flippy Avatar answered Nov 22 '25 08:11

flippy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!