Questions tagged [linear-algebra]
For challenges involving linear algebra, the mathematics of vector spaces and linear mappings between them.
57 questions
18
votes
7
answers
2k
views
Seven-dimensional cross product
The cross product is a peculiarly 3-dimensional phenomenon. There are multiple ways of generalizing it, but each of them have trade offs.
If you require that a cross product be a product of two ...
14
votes
19
answers
3k
views
Antiparallel 12-hour Clock Hands
Output (or print) each of the 11 times, one per line, in the POSIX %I:%M:%S format, at which the hour and minute hands of a 12-hour clock are antiparallel. Here <...
12
votes
7
answers
2k
views
Contract a tensor
Introduction
Tensor contraction is an operation that can be performed on a tensor. It is a generalization of the idea of the trace of a matrix. For example, if we have a rank-2 tensor (a matrix) and ...
26
votes
41
answers
2k
views
Diagonalize a vector
Diagonalize a vector into a matrix.
Input
A vector, list, array, etc. of integers \$\mathbf{v}\$ of length \$n\$.
Output
A \$n \times n\$ matrix, 2D array, etc. \$A\$ such that for each element \$a_i \...
15
votes
13
answers
1k
views
Hankel transform of an integer sequence
A Hankel matrix is a square matrix in which each ascending skew-diagonal from left to right is constant, e.g.:
$$\begin{bmatrix} a & b & c & d \\ b & c & d & e \\ c & d &...
7
votes
2
answers
525
views
NxM List Combination Closest to Target
Given a list of N lists, each containing M positive integers, and a separate list of M positive integers (target values), return a list of N scalars (integers with a value of 0 or more) that ...
15
votes
7
answers
824
views
Are these the basis vectors?
A basis of a vector space \$V\$ is a set of vectors \$B\$ such that every vector \$\vec v \in V\$ can be uniquely written as a linear combination of the vectors in \$B\$. In other words, let \$B = \{\...
16
votes
4
answers
801
views
Bad matrix multiplication that gives the right answer
Executive summary:
Print NxN matrices \$A\$ and \$B\$ where \$ AB = 10A + B \$. Largest N wins!
Details:
Entrants in this challenge should choose an N. Submit a program that takes an input integer '...
17
votes
10
answers
1k
views
Decomposition of a matrix in \$ SL_2(\mathbb{Z}) \$
Background
The special linear group \$ SL_2(\mathbb{Z}) \$ is a multiplicative group of \$ 2 \times 2 \$ matrices whose elements are integers and determinant is 1.
It is known that every member of \$...
6
votes
6
answers
652
views
Explore a Klarner-Rado sequence [duplicate]
One of the Klarner-Rado sequences is defined as follows:
the first term is \$1\$
for all subsequent terms, the following rule applies: if \$x\$ is present, so are \$2x+1\$ and \$3x+1\$
the sequence ...
29
votes
8
answers
6k
views
Billiard balls collision
Given the 2-dimensional positions and velocities of a pair of billiard balls right before impact, calculate their velocities after a perfectly elastic collision. The balls are assumed to be ideal ...
24
votes
18
answers
5k
views
Find the inverse of a 3 by 3 matrix
Challenge
Given nine numbers, a, b, c, d, e, f, g, h, i, as input which correspond to the square matrix:
$$\mathbf{M} = \begin{pmatrix}a& b& c\\ d& e&...
13
votes
9
answers
3k
views
Calculate the Hafnian as quickly as possible
The challenge is to write the fastest code possible for computing the Hafnian of a matrix.
The Hafnian of a symmetric 2n-by-2n ...
31
votes
10
answers
1k
views
Find the dot product of Rationals
I was at a friend's house for dinner and they suggested the idea of a "Prime-factor vector space". In this space the positive integers are expressed as a vector such that the nth element in the ...
14
votes
13
answers
3k
views
Characteristic polynomial
The characteristic polynomial of a square matrix \$A\$ is defined as the polynomial \$p_A(x) = \det(Ix-A)\$ where \$I\$ is the identity matrix and \$\det\$ the determinant. Note that this definition ...
12
votes
5
answers
852
views
Solve a matrix equation by Jacobi's method (Revised)
Mathematical Background
Let A be an N by N matrix of real numbers, b a vector of N real numbers and x a vector N unknown real numbers. A matrix equation is Ax = b.
Jacobi's method is as follows: ...
22
votes
14
answers
2k
views
Is the matrix rank-one?
Given a matrix of integers, test if it's rank-one, meaning that every row is a multiple of the same vector. For example, in
...
27
votes
10
answers
4k
views
Symbolic matrix multiplication
There are lots of different ways to explain matrix multiplication. I'll stick with a single figure since I believe most people here are familiar with it (and the figure is very descriptive). If you ...
15
votes
3
answers
518
views
Totally Invertible Submatrices
(inspired by this question over on Math)
The Definitions
Given an n x n square matrix A, we can call it invertible if there ...
10
votes
14
answers
832
views
Dot Product of Diagonals
This challenge is very simple. You are given as input a square matrix, represented in any sane way, and you have to output the dot product of the diagonals of the matrix.
The diagonals in specific are ...
20
votes
5
answers
1k
views
Jordan Decomposition
Important note: Because this challenge only applies to square matrices, any time I use the term matrix, it is assumed that I am referring to a square matrix. I am leaving off the “square” description ...
13
votes
11
answers
2k
views
Calculate the Kronecker Product
Related, but very different.
In the examples below, \$A\$ and \$B\$ will be \$2\times2\$ matrices, and the matrices are one-indexed.
A Kronecker product has the following properties:
...
9
votes
6
answers
1k
views
Calculate the Kronecker sum of two matrices
In the examples below, A and B will be 2-by-2 matrices, and the matrices are one-indexed.
A Kronecker product has the ...
13
votes
6
answers
2k
views
Solve a Linear Equation
This challenge but with a better spec.
Spec
Your program will take a linear equation containing a single variable x and output the value of ...
18
votes
12
answers
1k
views
Recursive 2x2 determinant
The determinant of a 2 by 2 matrix
a b
c d
is given by ad - bc.
Given a matrix of digits with dimensions 2n by 2n, n ≥ 1, ...