MathNumericsを使う

VSでTools -> Nuget Package Manager -> Nuget Package Console

Install-Package MathNet.Numerics -Version 4.15.0

www.nuget.org

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using MathNet.Numerics.LinearAlgebra.Double;

namespace MathNumericsPractice
{
    class Program
    {
        static void Main(string[] args)
        {
            // initialize the matrix
            var matrixAho = DenseMatrix.OfArray(new double[,] { { 1.0, 2.0, 3.0 }, { 4.0, 5.0, 6.0 }, { 7.0, 9.0, 8.0 } });
            // Obtain inverse matrix
            var matrixInverseOfAho = matrixAho.Inverse();

            Console.WriteLine($"{nameof(matrixAho)}");
            Console.WriteLine(matrixAho);
            Console.WriteLine($"{nameof(matrixInverseOfAho)}");
            Console.WriteLine(matrixInverseOfAho);
            Console.WriteLine($"{nameof(matrixAho)} x {nameof(matrixInverseOfAho)} shall be indentity matrix");
            Console.WriteLine(matrixAho * matrixInverseOfAho);
        }
    }
}