nero_bin
nero_bin

Reputation: 65

Solving linear equations where each matrix element itself is matrix (2D) and each variables are 1D vectors

The simple example of the problem is: $Ax = b$

In my case:

enter image description here

Any idea/suggestion is highly appreciated.

Upvotes: 0

Views: 383

Answers (1)

chthonicdaemon
chthonicdaemon

Reputation: 19760

As long as the dimensions conform, A is actually "just" a matrix, even if it is built out of smaller matrices. Here's a relatively general example showing how the dimensions must go:

import numpy
import numpy.linalg

l, m, n, k = 2, 3, 4, 5

# if these are known, obviously just define them here.
A11 = numpy.random.random((l, m))
A12 = numpy.random.random((l, n))
A21 = numpy.random.random((k, m))
A22 = numpy.random.random((k, n))
x1 = numpy.random.random((m,))
x2 = numpy.random.random((n,))

A = numpy.bmat([[A11, A12], 
                [A21, A22]])
x = numpy.concatenate([x1, x2])

b = numpy.linalg.solve(A, x)

Upvotes: 2

Related Questions