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, 08 Feb 2023 18:32:57 +0100Is it no longer possible to calculate SVD in sage?https://ask.sagemath.org/question/66289/is-it-no-longer-possible-to-calculate-svd-in-sage/ I recently noticed that the property `.SVD()` is no longer available for matrices defined over the `RDF` ring.
Is it no longer possible to calculate singular value decomposition in sage?more_weightWed, 08 Feb 2023 18:32:57 +0100https://ask.sagemath.org/question/66289/Copying a Matrixhttps://ask.sagemath.org/question/40754/copying-a-matrix/I'm trying to take the Singular Value Decomposition of the adjacency matrix of a graph A, but all my "reasonable" attempts at doing so have failed, see the code below.
I believe the problem has something to do with the matrix being immutable, so I've been trying to copy A into a different matrix M and then perform SVD on M. he only thing that I've found to work is to essentially build A from scratch, but there must be a better method.
sage: A=graphs.CycleGraph(3).adjacency_matrix()
#Method 1: Try and get SVD directly from A; gives error at last step.
#sage: A.change_ring(RDF)
#sage: A.SVD()
#Method 2: Try and copy A to a different matrix and then do SVD; gives error at last step.
# sage: M=copy(A)
# sage: M.change_ring(RDF)
# sage: M.SVD()
#Method 3: Build A up again from scratch and then do SVD; works, but is tedious.
sage: M=matrix(RDF,3,3)
sage: for i in [0..2]:
for j in [0..2]:
if(A[i,j]==1):
M[i,j]=1
sage: M.SVD()zorkkoiTue, 23 Jan 2018 19:44:19 +0100https://ask.sagemath.org/question/40754/Linear equations with errorshttps://ask.sagemath.org/question/24152/linear-equations-with-errors/I have a system of $n^2$ homogeneous linear equations in $n^2$ variables.
Each equation is sparse and only involves $2n$ variables.
I create a list of equations and use solve(). I only get the "all-zero" solution. This is because of inaccuracies in the equations. I know (from theory) that there is be a nonzero kernel.
So, I'd like to find an approximate solution. That is - a solution of norm 1, which "almost fulfills" the equations.
Behind the scenes I probably need the SVD decomposition of the matrix describing the equations (or at least, the input vectors corresponding to the small singular values).
> 1. Do I have to create a matrix to represent the equations, or can I use my equations directly?
> 2. Can it be a sparse matrix?
> 3. Do I have to use an SVD routine, or is there some convenient way to solve my problem directly?
> 4. Do you have an example of how to do it?orenTue, 16 Sep 2014 18:04:30 +0200https://ask.sagemath.org/question/24152/Can I get a exact solution for SVD?https://ask.sagemath.org/question/8866/can-i-get-a-exact-solution-for-svd/Here's an example.
<Code>
A=matrix(RDF,2,2,[1/2,-1/2,-1/2,1/2])
A.SVD()
<Result>
(
[-0.707106781187 0.707106781187]
[ 0.707106781187 0.707106781187],
[ 1.0 0.0]
[ 0.0 7.85046229342e-17],
[-0.707106781187 0.707106781187]
[ 0.707106781187 0.707106781187]
)
The exact solution is -1/sqrt(2),1/sqrt(2), 1/sqrt(2), 1/sqrt(2)
and D=(1, 0),(0, 0)
Something like this... http://www.wolframalpha.com/input/?i=SVD+%7B%7B1%2F2%2C+-1%2F2%7D%2C%7B-1%2F2%2C+1%2F2%7D%7D
Is there a way to get the exact solution?
One more question...
Why doesn't the next code work?
<Code>
A=matrix(RR,2,2,[1/2,-1/2,-1/2,1/2])
A.SVD()
QuantLabIdSat, 07 Apr 2012 10:53:22 +0200https://ask.sagemath.org/question/8866/