linear-algebra

Solve the linear equations system AX = B in Python, np.linalg.solve not working

痴心易碎 提交于 2021-01-29 11:29:42
问题 I'm trying to solve the linear equation AX=B where A,X,B are Matrices. I've tried using the np.linalg.solve function of numpy but the result seems to be wrong. Example: Matrix A [9 1 8] [3 2 5] [1 6 5] Matrix B [7 0 5] [7 8 4] [5 6 7] So to solve X, i've used: X = np.linalg.solve(A,B) The result is: X [ 1.17521368 -0.17948718 0.40598291] [ 0.20512821 -0.30769231 0.74358974] [-0.56410256 -0.15384615 1.20512821] But if i try to verify the result by multiplying A by X, the result is anything but

Finding the rotation matrix between two vectors in Python

早过忘川 提交于 2021-01-29 07:09:30
问题 I am trying to write a code that gives me the rotation matrix between two vectors. I have tried the code given as an answer to this question. I first make it calculate the rotation matrix and then test it to see if it gives the correct answer. However, it doesn't seem to be giving the correct answer. Could anyone help with why I can't get the correct answer with this? The Code is below: import numpy as np def rotation_matrix_from_vectors(vec1, vec2): a, b = (vec1 / np.linalg.norm(vec1))

SAGE: Automorphism group of finite abelian group?

痞子三分冷 提交于 2021-01-28 17:28:37
问题 For a finite abelian group G, say, G = AbelianGroup((4,4,5)) , I want Sage to return the automorphism group of G. Is this implemented? 回答1: You can get it partway easily. G = AbelianGroup((4,4,5)) gap(G).AutomorphismGroup() Group( [ Pcgs([ f1, f2, f3, f4, f5 ]) -> [ f1*f3*f4, f2*f4, f3*f4, f4, f5 ], Pcgs([ f1, f2, f3, f4, f5 ]) -> [ f1*f3*f4, f2*f4, f3*f4, f4, f5 ], Pcgs([ f1, f2, f3, f4, f5 ]) -> [ f1, f2, f1*f2*f3, f2*f4, f5 ], Pcgs([ f1, f2, f3, f4, f5 ]) -> [ f1, f2, f2*f3*f4, f4, f5 ],

Converting SuiteSparse.SPQR.QRSparseQ to SparseMatrixCSC?

依然范特西╮ 提交于 2021-01-28 11:17:46
问题 I have this problem that converting the native sparse format for the QR decomposition of a sparse Matrix takes forever. However, I need it in the CSC format to use it for further computations. using LinearAlgebra, SparseArrays N = 1000 A = sprand(N,N,1e-4) @time F = qr(A) @time F.Q @time Q_sparse = sparse(F.Q) 0.000420 seconds (1.15 k allocations: 241.017 KiB) 0.000008 seconds (6 allocations: 208 bytes) 6.067351 seconds (2.00 M allocations: 15.140 GiB, 36.25% gc time) Any suggestions? 回答1:

Finding all solutions of a non-square linear system with infinitely many solutions

让人想犯罪 __ 提交于 2021-01-28 09:25:58
问题 In this question was found a solution to find a particular solution to a non-square linear system that has infinitely many solutions. This leads to another question: How to find all the solutions for a non-square linear system with infinitely many solutions, with R? (see below for a possible description of the infinite set of solutions) Example: the linear system x+y+z=1 x-y-2z=2 is equivalent to A X = B with: A=matrix(c(1,1,1,1,-1,-2),2,3,T) B=matrix(c(1,2),2,1,T) A [,1] [,2] [,3] [1,] 1 1 1

Finding all solutions of a non-square linear system with infinitely many solutions

让人想犯罪 __ 提交于 2021-01-28 09:25:24
问题 In this question was found a solution to find a particular solution to a non-square linear system that has infinitely many solutions. This leads to another question: How to find all the solutions for a non-square linear system with infinitely many solutions, with R? (see below for a possible description of the infinite set of solutions) Example: the linear system x+y+z=1 x-y-2z=2 is equivalent to A X = B with: A=matrix(c(1,1,1,1,-1,-2),2,3,T) B=matrix(c(1,2),2,1,T) A [,1] [,2] [,3] [1,] 1 1 1

How to find the common eigenvectors of two matrices with distincts eigenvalues

你说的曾经没有我的故事 提交于 2021-01-27 04:07:51
问题 I am looking for finding or rather building common eigenvectors matrix X between 2 matrices A and B such as : AX=aX with "a" the diagonal matrix corresponding to the eigenvalues BX=bX with "b" the diagonal matrix corresponding to the eigenvalues where A and B are square and diagonalizable matrices. I took a look in a similar post but had not managed to conclude, i.e having valid results when I build the final wanted endomorphism F defined by : F = P D P^-1 I have also read the wikipedia topic

How to find the common eigenvectors of two matrices with distincts eigenvalues

孤人 提交于 2021-01-27 04:04:08
问题 I am looking for finding or rather building common eigenvectors matrix X between 2 matrices A and B such as : AX=aX with "a" the diagonal matrix corresponding to the eigenvalues BX=bX with "b" the diagonal matrix corresponding to the eigenvalues where A and B are square and diagonalizable matrices. I took a look in a similar post but had not managed to conclude, i.e having valid results when I build the final wanted endomorphism F defined by : F = P D P^-1 I have also read the wikipedia topic

How to find the common eigenvectors of two matrices with distincts eigenvalues

我们两清 提交于 2021-01-27 04:02:06
问题 I am looking for finding or rather building common eigenvectors matrix X between 2 matrices A and B such as : AX=aX with "a" the diagonal matrix corresponding to the eigenvalues BX=bX with "b" the diagonal matrix corresponding to the eigenvalues where A and B are square and diagonalizable matrices. I took a look in a similar post but had not managed to conclude, i.e having valid results when I build the final wanted endomorphism F defined by : F = P D P^-1 I have also read the wikipedia topic

Implementing the Bartels–Stewart algorithm in Eigen3?

旧时模样 提交于 2021-01-03 10:28:19
问题 In the past when I've needed to solve the Sylvester equation, AX + XB = C , I've used scipy 's function, solve_sylvester [1], which apparently works by using the Bartels-Stewart algorithm to get things into upper triangular form, and then solving the equation using lapack . I now need to solve the equation using eigen . eigen provides an function, matrix_function_solve_triangular_sylvester [2], which seems by the documentation to be similar to the lapack function which scipy calls. I'm