# Questions tagged [linear-algebra]

Linear Algebra is a core body of mathematics studying vector spaces and linear mappings between these spaces. Key topics include: matrices, vectors, simultaneous systems of linear equations, diagonal form, eigenvalues, eigenvectors, projections, points, lines, planes, hyperplanes, rotations and reflections.

2,848 questions
53 views

### Solving n linear systems efficiently

I have n (very large) independent linear systems (Ax = b_i). They all have the same A, but b_i is different for (i = 1, ..., n). I want to solve these n systems in parallel in CUDA. I was thinking ...
26 views

### Suppress negligible complex numpy eigenvalues?

I am calculating the eigenvalues of a covariance matrix, which is real and symmetric positive semi-definite. Therefore, the eigenvalues and eigenvectors should all be real, however numpy.linalg.eig() ...
7 views

### Jacobi Method with many zero terms FLOPs

I am given a 100x100 matrix in a system and in a general case, it takes bigO(n^2) flops to do each sweep of the Jacobi method so if you have to do 100 sweeps, it becomes as inefficient as running ...
31 views

### Calling numDeriv:hessian() with multiple-parameter-objective-function in Rcpp

My aim is to call the hessian() function from the numDeriv R package from a cpp file (using Rcpp). A toy example: I want to calculate a hessian of a one-dimensional function x^n at the point x=1 ...
43 views

### Problem with the Frobenius norm between a matrix and its approximation using SVD implemented in Python

According to Theorem 18.4 of the IR book, the Frobenius error between a matrix and its approximation obtained by zeroing out the k smallest singular values are equal to the largest removed singular ...
18 views

### numpy.linalg.solve returns a solution for a matrix that is not full rank

I've been learning the basics of OLS regression, and was told that there can't be perfect multicolinearity in the model. I have a matrix that is obviously not of full rank: np.linalg.matrix_rank(...
33 views

### SciPy: Symmetric permutation of sparse CSR matrix

I'd like to symmetrically permute a sparse matrix, permuting rows and columns in the same way. For example, I would like to rotate the rows and columns, which takes: 1 2 3 0 1 0 0 ...
48 views

### Make a camera rotate along z axis while moving and changing lookAt (rollercoaster view) in Three.js

Hi i am having a problem maybe you can help me. I have a camera that is going down a tube following a path. and a camera that rotates around that tube always pointing toward the next point in the ...
60 views

### Printing a complex matrix Fortran

The complex matrix is declared this way: complex(8) :: matrix(:,:) How can I print this matrix with each element as: (a, b) or a+ib, and in a nxn format? (by that I mean as a square matrix, with a ...
61 views

### Getting negative S value from SVD decomposition in Numpy?

I want to whiten the CIFAR10 dataset using ZCA. The input X_train is of shape (40000, 32, 32, 3) where 40000 is the number of images, and 32x32x3 is the size of each image. I'm using the code from ...
35 views

### Eigen-values of covariance matrix usign QR factorization

Given the matrix X of dimension D x N, I am interested to compute the eigen-values of C = np.dot(X, X.T)/N using QR factorization. Based on following: we expect the eigen-values of C to be np.diag(r....
21 views

### What is the difference between a Metric and a Norm?

From my understanding, a metric defines a more abstract entity than a norm, but I don't feel like I truly understand. Can someone please explain it to me in layman's terms?
95 views

### How to solve a linear system of a square matrix in C++ when the matrix has no LU-Decomposition?

I have been trying to develop a program to solve a system Ax=b for a square matrix A using LU-Decomposition. However, I realized that this decomposition does not always exist (one way to tell is if a ...
12 views

### Solving symmetric linear equation with constraint

I want to solve the equation Ax = b with the constraints that x >= 0. The matrix A is symmetric and it is sparse. What is the best algorithm or method to solve this ?. I also would like to know the ...
37 views

### Eigen library, Jacobi SVD

I'm trying to estimate a 3D rotation matrix between two sets of points, and I want to do that by computing the SVD of the covariance matrix, say C, as follows: U,S,V = svd(C) R = V * U^T C in my ...
27 views

### How can I use TCL linear algebra package for setting the elemnt of a matrix

I am trying to use the ::math::linearalgebra:: package to do some simnple eigenvalue calculation for testing. The following code works and produces the desired result: package require math package ...
18 views

### Eigenvalues and Eigenvectors of circulant matrix and its transpose

This is a very simple question, but somehow I'a unable to find the answer for it. Any help will be appreciated. Suppose that A is a circulant matrix. Now both A and its transpose have the same set ...
75 views

### Change of basis in numpy

Given two basis matrices basis_old and basis_new in numpy, is there a function somewhere in the library to get the transformation matrix to convert a vector vec in basis_old to its representation in ...
51 views

### How to write functions for computing matrix inverse and solve in cython using lapack, without python objects?

I am trying to write Cython functions to compute inverses and obtain solutions to linear systems. I know this is what Numpy does. But I need use these functions in another loop I'm writing in Cython. ...
18 views

### Sparse matrix diagonalisation using Numpy Linalg package

What is the maximum size of a sparse matrix that can be diagonalized using Numpy Linalg package? I have been working with exact diagonalisation methods such as Lanczos and Arnoldi in the context of ...
16 views

### Expokit realization on Python

I am looking for a Pythonic realization of Expokit, which is a software package that provides matrix exponential routines for small dense or very large sparse matrices, real or complex, i.e. it finds ...
30 views

### Find Independent Vectors (High Performance)

I'm in desperate need of a high performance algorithm to reduce a matrix to its independent vectors (row echelon form), aka find the basis vectors. I've seen the Bareiss algorithm and Row Reduction ...
20 views

### Sample an embedding matrix which goes through one or two lower-dimensional points

Assume I have two points x1 and x2 which are 2-dimensional. How can I efficiently generate (optimally using numpy for example or any other linalg library) an embedding matrix, which is of dimensions (...
55 views

### C program solving parametric equations

Let's say you have N equations with M parameters. Task is to find if there is any solution. If there is, which one. If there are more solutions, how do you describe them ? example: 1) x + y + z = 1 ...
61 views

### Checking that a matrix is positive semidefinite with a given rank (in Julia)

I am writing a function that checks if a matrix X is positive semidefinite with a given rank k. To do this, I compute the eigenvalues of X, and I check that exactly k of them are positive and the rest ...
35 views

### How to avoid SIGSEV Segmentation fault in C when allocating random elements to an int 2D matrix in a function? [closed]

I am doing an assignment where we are required to assign random integers to a 5x5 matrix using array notation (so cannot use pointers here). After looking at this closed Les Vesti non-question, I ...
26 views

### How can I combine 3 vectors sideways in NumPy?

I have 3 arrays [x1,y1,z1], [x2,y2,z2], [x3,y3,z3] how do I get [[x1,x2,x3], [y1,y2,y3], [z1,z2,z3]]? I could do: result = np.array([[a1,a2,a3], [a1,a2,a3], [a1,a2,a3]] ...
56 views

### How to implement orthogonal matching pursuit(OMP) algorithm in CUDA for GPU?

OMP algorithm can be divided in three parts in parallel programming: matrix-vetor multiplication, sorting (to search the maximal absolute value of projection from unselected atoms) and least square. ...
47 views

### Constraint of Ordinary Least Squares using Scipy / Numpy

I am trying to solve the set of linear equations: min || Ax - B ||^2 for t in [0,1] such that the coefficients x in this equation satisfy the linear equation: C x = D This system attempts to ...
46 views

### Finding SVD matrices of a complex matrix in Java

I am currently working on an audio signal processing project and need to use SVD on a complex matrix in Java. My current linear algebra library is Apache Commons. However, it only provides SVD of real ...
33 views

### Fast integer matrix null space in Python?

I have a Python program that accepts matrices with coefficients that can only be -1, 0 and 1. I need to compute the null space for those matrices. Those matrices can be huge (millions of entries) and ...
51 views

### under determined system solution python

Goal: calculate a vector from under determined linear system (2x3) Ax = b The third equation should be unity equation (x^2 + y^2 + z^2 = 1). I have correct matrix coefficients, but can't get the ...
16 views

### Getting a desired vector from lsqr in python when solving a linear system

I am trying to solve a linear system which has multiple solutions. Here is part of my code: from scipy.sparse.linalg import lsqr solution = lsqr(M, b) Now, if the matrix M is this: [1 1 1 1] [...
44 views

### Scalar-Vector multiplication with meshgrid (Matlab)

I have an expression such as s=aU+bV, where a and b are scalars and U and V 3-component vectors. The output s is clearly a 3-component vector. Let's assume I want to plot the first component of s find ...
42 views

### Block matrix inner products in Matlab

I have been using the following custom function to perform the multiplication of a vector by a matrix, in which each element of the vector multiplies a 3x3 block within a (3xN)x(3) matrix: function [...
56 views

### Block-diagonal Schur factorization in Python

I have a real non-diagonalizable matrix that I'm looking to decompose as tidily as possible. I would love to put it in Jordan normal form, but since that's problematic numerically I'm looking for the ...
44 views

### Closed Form Ridge Regression

I am having trouble understanding the output of my function to implement multiple-ridge regression. I am doing this from scratch in Python for the closed form of the method. This closed form is shown ...
49 views

### Eigen: Obtain the kernel of a sparse matrix

Given a sparse matrix A and a vector b, I would like to obtain a solution x to the equation A * x = b as well as the kernel of A. One possibility is to convert A to a dense representation. #include &...
50 views

### Why does numpy.linalg.solve() have non-constant computation time for same sized arrays?

I've been using numpy.linalg.solve(A,B) to solve a linear equation. In my case: A is about 10,000x10,000 and B is around 10,000x5. If I initialize A and B randomly using: A = numpy.random.rand(10000,...
28 views

### What am I doing wrong with this maximization problem?

I am getting the ValueError: shapes (6,) and (1,6) not aligned: 6 (dim 0) != 1 (dim 0). The error occurs when I execute the maximization problem in line 23. Do you know what can I change in this code ...
46 views

### How to approximate a line from points

I'm looking for a simple implementation of total least squares. Or any other way to approximate a line from a set of points that doesn't discriminate between the x- and y-axes. I have been able to ...
50 views

### Getting the Closest Points between Polygons with the GJK Algorithm

I am trying to implement the GJK algorithm by following this lecture. For the most part, it is working, but sometimes 1 of the 2 closest points is incorrect. Here are two examples: EXAMPLE 1: The ...
49 views

### How can I omit a row-operation for elements in the diagonal

I'm trying to create a program which solves linear systems using Gaussian Elimination. The program should consist of two parts. The forwards phase and a phase for Back-substitution. Right now I am ...
65 views

### Singular matrix C in LSQ subproblem - What does it mean?

I am trying to solve an Inverse Kinematics (IK) task as an optimisation problem using Python and SciPy. There exists a robot arm in a 2D environment, and I want to reach for a specific target in the ...
28 views

### Python: given a plane equation draw a subset of points that belong to it

As the title say, let's assume I have a plane equation: ax+by+cz=d (e.g. -4x + 5y + 9z = -9) I want to draw n random points (let's say 500) that belong to that plane. Can somebody help me with ...
61 views

### More general or efficient approach for this matrix multiplication?

In R, is there a more efficient and/or general way to produce the desired output from the two matrices below? I'm suspicious that what I've done is just some esoteric matrix multiplication operation ...
37 views

### Vector and Matrix classes for linear algebra in Spark 2.4

Does Spark 2.4 have Vector and Matrix classes that support basic linear algebra operations like dot product, norm, matrix and vector multiplication? I can't find any linear algebra support in classes ...
95 views

### Doing basic linear algebra in Spark 2.4

Does Spark 2.4 have Vector and Matrix classes that support basic linear algebra operations like dot product, norm, matrix and vector multiplication? I can't find any linear algebra support in classes ...