using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Science.Mathematics.LinearAlgebra { public class BlockMatrix : Matrix { private Matrix[,] a; public BlockMatrix(Matrix[,] A) { a = A; int r = 0, c = 0; for (int i = 0; i < A.GetLength(0); i++) r += A[i, 0].SizeOfRow; for (int j = 0; j < A.GetLength(1); j++) c += A[0, j].SizeOfColumn; sr = r; sc = c; el = new double[sr, sc]; int c1 = 0, c2 =0; for (int i = 0; i < A.GetLength(0); i++) for (int j = 0; j < A[i, 0].SizeOfRow; j++) { c2 = 0; for (int k = 0; k < A.GetLength(1); k++) for (int l = 0; l < A[0, k].SizeOfColumn; l++) { el[c1,c2] = A[i, k][j,l]; c2++; } c1++; } } public Matrix[,] Element { get { return a; } } public static BlockMatrix operator *(BlockMatrix A, BlockMatrix B) { Matrix[,] ma = new Matrix[A.Element.GetLength(0),B.Element.GetLength(1)]; for (int i = 0; i < A.Element.GetLength(0); i++) for (int j = 0; j < B.Element.GetLength(1); j++) { ma[i, j] = new Matrix(A.Element[i, 0].SizeOfRow, B.Element[0, j].SizeOfColumn); for (int k = 0; k < A.Element.GetLength(1); k++) ma[i,j] = (A.Element[i,k]*B.Element[k,j])+ ma[i,j]; } BlockMatrix C = new BlockMatrix(ma); return C; } } }