using System; using System.Collections.Generic; using System.Linq; using System.Text; using L = Science.Mathematics.LinearAlgebra; namespace Strang3Ed.Chapter02.Section4 { public class ExampleB { public ExampleB() { } private string result; public string Result { get { return result; } } public void Compute() { L.Matrix[,] a = new L.Matrix[2, 2]; L.Matrix[,] b = new L.Matrix[2, 2]; L.Matrix[,] c = new L.Matrix[2, 2]; double[,] p = {{1.0,3.0}, {4.0,-1.0}}; double[,] zero = {{0.0,0.0}, {0.0,0.0}}; a[0, 0] = new L.Matrix(p); a[1, 1] = new L.Matrix(p); a[0, 1] = new L.Matrix(zero); a[1, 0] = new L.Matrix(zero); b[0, 0] = new L.IdentityMatrix(2); b[1, 1] = new L.IdentityMatrix(2); b[0, 1] = new L.IdentityMatrix(2); b[1, 0] = new L.Matrix(zero); double[,] z = {{-1.0,3.0}, {4.0,7.0}}; c[0, 0] = new L.Matrix(zero); c[1, 1] = new L.Matrix(zero); c[0, 1] = new L.Matrix(z); c[1, 0] = new L.Matrix(zero); L.BlockMatrix A = new L.BlockMatrix(a); L.BlockMatrix B = new L.BlockMatrix(b); L.BlockMatrix C = new L.BlockMatrix(c); result += A.ToString() + "\r\n"; result += B.ToString() + "\r\n"; result += C.ToString() + "\r\n"; result += ((A * B) - (B * A)).ToString() + "\r\n"; result += ((B * C) - (C * B)).ToString() + "\r\n"; } } } /* 1 3 0 0 4 -1 0 0 0 0 1 3 0 0 4 -1 1 0 1 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0 -1 3 0 0 4 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */