ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 28 Apr 2021 13:31:54 +0200Issue with inversion of complex symbolic array initialized with numpyhttps://ask.sagemath.org/question/56850/issue-with-inversion-of-complex-symbolic-array-initialized-with-numpy/Hello!
I am trying to invert a symbolic matrix that is initialized with a combination of numpy arrays and I get an error. Below i present a simple code that gives the error.
import numpy as np
a = np.zeros((5,5) , dtype = 'complex')
np.fill_diagonal(a,1)
b = var('x')*a
c = matrix(b)
c.inverse()
Gives the error:
> ECL says: THROW: The catch
> MACSYMA-QUIT is undefined.
What I have noticed up until now is that the issue stems from the data type. When I try casting the numpy array to float before turning it into a matrix, it works. However, my actual code makes use of complex coefficients. I believe it might have to do with how the imaginary part is represented in SageMath in comparison to numpy. ( `j` vs `I` )
When I manually create the symbolic array with `I` for the imaginary part, the `.inverse()` has no issue.yorgos_sotWed, 28 Apr 2021 13:31:54 +0200https://ask.sagemath.org/question/56850/can't display the inverse of complex matrixhttps://ask.sagemath.org/question/47326/cant-display-the-inverse-of-complex-matrix/ Hi
it seems that Sagemath is able to calculate this matrix inverse, but it is unable to display it.
Maybe someone will explain me why ? it is not easy to find what I do wrong because there is no error message for n=8
an it's ok for n=4
#FFT
w=var('w')
n=8
FFT=matrix(SR,n,n)
#show (FFT)
for i in (0..n-1):
for j in (0..n-1):
FFT[i,j]=w^(i*j)
FFTc=1/sqrt(n) *FFT.subs(w=e^(2*I*pi/n))
#show(" FFTc : ",FFTc)
FFTc.change_ring(CC)
show(" FFTc.right_kernel().matrix() : ",FFTc.right_kernel().matrix())
show (" FFTc.determinant() for n =",str(n),": ",FFTc.determinant())
FFTcI=copy(FFTc).inverse()
#show (" FFT w :",FFT)
show (" FFTc with w=e^(2*I*pi/",str(n),") : ",FFTc)
show (" FFTc inverse with w=e^(2*I*pi/",str(n),") : ",FFTcI)
ortolljWed, 31 Jul 2019 18:19:16 +0200https://ask.sagemath.org/question/47326/Moore-penrose-inverse with Sage?https://ask.sagemath.org/question/23244/moore-penrose-inverse-with-sage/ How to compute the moore-penrose inverse of a matrix?
What I have found is using Scipy (or Numpy):
M = matrix(2,2,(1,2,2,4))
from scipy import linalg
matrix(linalg.pinv(M))
Any other way in Sage?ndomesMon, 07 Jul 2014 08:02:17 +0200https://ask.sagemath.org/question/23244/symbolic 2x2 block matrix inversionhttps://ask.sagemath.org/question/10799/symbolic-2x2-block-matrix-inversion/Is it possible in SAGE to get the 2x2 block matrix inversion described in [Wikipedia](https://en.wikipedia.org/wiki/Block_matrix_pseudoinverse#Block_matrix_inversion)?
I looked at [this question](http://ask.sagemath.org/question/3245/determinant-of-block-matrices) about the determinant of block matrices, and at [this question](http://ask.sagemath.org/question/505/symbolic-matrices) about symbolic matrices, and tried the following code on the [cloud](http://www.sagenb.org/):
A = matrix(SR, 2, 2, 'a1 a2 a3 a4'.split(' '))
B = matrix(SR, 2, 2, 'b1 b2 b3 b4'.split(' '))
C = matrix(SR, 2, 2, 'c1 c2 c3 c4'.split(' '))
D = matrix(SR, 2, 2, 'd1 d2 d3 d4'.split(' '))
M = block_matrix(SR, 2, 2, [A, B, C, D])
Mi = M.inverse()
Mi.simplify_rational()
But it doesn't seem to be able to exactly reproduce the Wikipedia formula (it returns a horrible formula full of a1, a2, etc). Any idea?timflutreTue, 03 Dec 2013 17:05:46 +0100https://ask.sagemath.org/question/10799/Why functions are much slower than var in some calculations?https://ask.sagemath.org/question/8556/why-functions-are-much-slower-than-var-in-some-calculations/Hi,
I am doing symbolic calculations using sage. I want to take derivatives thus I defined some general functions. But I found the functions made other symbolic calculations much more slowly. For example:
a = function('a',t,x,y,z)
var('a1 a2 a3 a4')
# case 1
time matrix(SR, 2, [a,a2,a3,a4]).inverse()
# Time: CPU 0.23 s, Wall: 0.23 s
# case 2
time matrix(SR, 2, [a1,a2,a3,a4]).inverse()
# Time: CPU 0.01 s, Wall: 0.01 s
There is a big time difference simply because in case 1 a is a variable. When considering 4x4 matrices, the difference becomes huge.
I believe there are a few other command slowed down greatly by defining functions, because of the performance difference in my code. I haven't factored out them yet.
Any ideas to improve speed in this case? Thank you very much!tririverWed, 14 Dec 2011 21:44:55 +0100https://ask.sagemath.org/question/8556/Sage crashes when inverting a large matrix - alternatives?https://ask.sagemath.org/question/8501/sage-crashes-when-inverting-a-large-matrix-alternatives/I'm trying to find the inverse of a 50x50 dense matrix of rational numbers. The matrix is created using the method `matrix_from_rows` from another matrix that was created using `matrix(QQ,B)` from a list of lists of rational numbers `B`. The error I get is the following:
/usr/.../sage-4.7.1/local/bin/sage-sage: line 301: 27416 Killed sage-cleaner &>/dev/null
/usr/.../sage-4.7.1/local/bin/sage-sage: line 301: 27417 Killed sage-ipython "$@" -i
I'm doing this at the university, so the number of processors and RAM both seem to be infinite.
I wonder if there is an alternative. For example, I could try to invert the matrix in Mathematica or Maple. Is there an easy way to interface with them? Thank you!ZatrapadooMon, 21 Nov 2011 13:46:14 +0100https://ask.sagemath.org/question/8501/