use C# to do matrix manipulation for unity

using System;
using System.Collections;
using System.Collections.Generic;

using System.IO;
using LinearAlgebra.MatrixAlgebra;
using LinearAlgebra.VectorAlgebra;
using LinearAlgebra.LinearEquations;


namespace LinearAlgebra
{

    class Program
    {
        
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!\n\n");
            Matrix aa = Matrix.Eye(3);
            Matrix bb = (-1 * aa);
            Matrix cc = aa * bb ;
            Console.WriteLine(cc);
            IEnumerable<double> col = cc.GetColumn(0);
            Matrix kk = Utility.IEnumerableToMatrix(1, 3, col);
            Console.WriteLine(kk);
            IEnumerator ee= cc.GetDiagonal().GetEnumerator();
            for(int i = 0; i<3; i++)
            {
                ee.MoveNext();
                Console.WriteLine(ee.Current);
                
            }
            Console.WriteLine("Buffer Out!!");
            Console.WriteLine(ee.Current);
            
            Console.WriteLine(Utility.IEnumerableToMatrix(cc.RowCount,1,cc.GetDiagonal()));
            Console.WriteLine(cc.Equals(bb));

            double[] reals= cc.Eigen().Real;
            Console.WriteLine(Utility.ArrayToMatrix(1,reals.Length,reals));
            
            //The way to assign Matrix:First transform double[*] to double[*,*] using this ArraytoMatrix method;
            Matrix qq = new Matrix(Utility.ArrayToMatrix(1, reals.Length, reals));
            Console.WriteLine(qq);

            //The right way to use an enumerator
            IEnumerator enumerator = aa.GetColumn(0).GetEnumerator();
            while (enumerator.MoveNext())
            {
                Console.WriteLine($"Enumerator A is {enumerator.Current}");
            }
            
            //or if using enumerable array then foreach loop:
            foreach(var ii in aa.GetColumn(0))
            {
                Console.WriteLine($"A is {ii}");
            }

            Console.WriteLine(aa.Inverse());
            Console.WriteLine(cc.Inverse());
            Console.WriteLine(aa.Det());     //1
            Console.WriteLine(cc.Det());     //-1

            Console.WriteLine(aa.Count);
            Console.WriteLine(aa.ColumnCount);
            Matrix tanhaa = aa.Map(Math.Tanh);
            Console.WriteLine(tanhaa);
            Console.WriteLine(tanhaa.Power(2));
            Console.WriteLine(aa.Rank());
            aa.SetRow(0, aa.GetRow(1));
            Console.WriteLine(aa);

            Console.WriteLine(aa.Transpose());
            Console.WriteLine(aa);

            aa.SetDiagonal(aa.GetColumn(1));
            Console.WriteLine(aa);

            aa.Save(@"C:\Users\jerry\aa.txt");

            Console.WriteLine("Finish!!");
            double[][] jar = aa.ToJaggedArray();
            Console.WriteLine(jar[0][2]);

            Matrix aaload = Matrix.Load(@"C:\Users\jerry\aa.txt");
            Console.WriteLine(aaload);

            Matrix a1 = Matrix.cBind(Matrix.Random(3, 1), Matrix.Random(3, 2));
            Console.WriteLine(a1);


        }
    }
}

This file: Program.cs
and other dependencies (files) ->-> here ->-> in the same folder.

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 点我我会动 设计师:白松林 返回首页