public void btnTestEigenvalues_Click(IRibbonControl e)
        {
            Random rando = new Random();

            double[,] TwoArray = new double[500, 500];
            for (int i = 0; i < TwoArray.GetLength(0); i++)
            {
                for (int j = 0; j < TwoArray.GetLength(1); j++)
                {
                    TwoArray[i, j] = rando.NextDouble();
                }
            }
            List <double> ticks1 = new List <double>();
            List <double> ticks2 = new List <double>();

            for (int i = 0; i < 10; i++)
            {
                DiagnosticsMenu.StartStopwatch();
                double[] result1 = MatrixOps.RealEigenvalues_Accord(TwoArray);
                ticks1.Add(DiagnosticsMenu.StopStopwatch(TimeUnit.milliseconds));
                DiagnosticsMenu.StartStopwatch();
                result1 = null;
            }
            MessageBox.Show($"{ticks1.Average().ToString()} Accord");
        }
        public void btnTestTranspose_Click(IRibbonControl e)
        {
            Random rando = new Random();

            double[,] TwoArray = new double[1000, 1000];
            for (int i = 0; i < TwoArray.GetLength(0); i++)
            {
                for (int j = 0; j < TwoArray.GetLength(1); j++)
                {
                    TwoArray[i, j] = rando.NextDouble();
                }
            }

            List <double> ticks1 = new List <double>();
            List <double> ticks2 = new List <double>();

            //int equalTo = 16;
            for (int i = 0; i < 10; i++)
            {
                DiagnosticsMenu.StartStopwatch();
                var result1 = MatrixOps.Transpose(TwoArray);
                ticks1.Add(DiagnosticsMenu.StopStopwatch(TimeUnit.milliseconds));
                DiagnosticsMenu.StartStopwatch();
                var result2 = ThisAddIn.MyApp.WorksheetFunction.Transpose(TwoArray);
                ticks2.Add(DiagnosticsMenu.StopStopwatch(TimeUnit.milliseconds));
                //int places = TestEquality(result1, result2);
                //if (places < equalTo)
                //    equalTo = places;
                result1 = null;
                result2 = null;
            }
            MessageBox.Show($"{ticks1.Average().ToString()} Accord");
            MessageBox.Show($"{ticks2.Average().ToString()} VBA");
        }
        public void btnTestInverse_Click(IRibbonControl e)
        {
            Random rando = new Random();

            double[,] TwoArray = new double[100, 100];

            double[,] result1 = new double[100, 100];
            double[,] result2 = new double[100, 100];
            List <double> ticks1 = new List <double>();
            List <double> ticks2 = new List <double>();

            //int equalTo = 16;
            for (int i = 0; i < 50; i++)
            {
                for (int i2 = 0; i2 < TwoArray.GetLength(0); i2++)
                {
                    for (int j = 0; j < TwoArray.GetLength(1); j++)
                    {
                        TwoArray[i2, j] = rando.NextDouble();
                    }
                }

                DiagnosticsMenu.StartStopwatch();
                result1 = MatrixOps.MatrixInverse(TwoArray);
                ticks1.Add(DiagnosticsMenu.StopStopwatch(TimeUnit.milliseconds));
                DiagnosticsMenu.StartStopwatch();
                result2 = Utilities.Conversions.ConvertObjectArrayToDouble(ThisAddIn.MyApp.WorksheetFunction.MInverse(TwoArray));
                //result2 = ThisAddIn.MyApp.WorksheetFunction.MInverse(TwoArray);
                ticks2.Add(DiagnosticsMenu.StopStopwatch(TimeUnit.milliseconds));
            }
            ThisAddIn.MyApp.ActiveSheet.Range("A1").Value         = "Original Matrix";
            ThisAddIn.MyApp.ActiveSheet.Range("A2:CV101").Value   = TwoArray;
            ThisAddIn.MyApp.ActiveSheet.Range("A102").Value       = "Accord Inverse";
            ThisAddIn.MyApp.ActiveSheet.Range("A103:CV202").Value = result1;
            ThisAddIn.MyApp.ActiveSheet.Range("A203").Value       = "VBA Matrix";
            ThisAddIn.MyApp.ActiveSheet.Range("A204:CV303").Value = result2;

            MessageBox.Show($"ACC v VBA Precision: {TestEquality(result1, result2, 9)}");

            MessageBox.Show($"{ticks1.Average().ToString()} Accord");
            MessageBox.Show($"{ticks2.Average().ToString()} VBA");
        }
        public void btnTestDeterminant_Click(IRibbonControl e)
        {
            Random rando = new Random();

            double[,] TwoArray = new double[5, 5];


            List <double> ticks1 = new List <double>();
            List <double> ticks2 = new List <double>();

            int equalTo = 16;

            for (int i = 0; i < 10; i++)
            {
                for (int i2 = 0; i2 < TwoArray.GetLength(0); i2++)
                {
                    for (int j = 0; j < TwoArray.GetLength(1); j++)
                    {
                        TwoArray[i2, j] = rando.NextDouble();
                    }
                }

                DiagnosticsMenu.StartStopwatch();
                double result1 = MatrixOps.Determinant(TwoArray);
                ticks1.Add(DiagnosticsMenu.StopStopwatch(TimeUnit.ticks));
                DiagnosticsMenu.StartStopwatch();
                double result2 = ThisAddIn.MyApp.WorksheetFunction.MDeterm(TwoArray);
                ticks2.Add(DiagnosticsMenu.StopStopwatch(TimeUnit.ticks));
                int places = TestEquality(result1, result2);
                if (places < equalTo)
                {
                    equalTo = places;
                }
                result1 = 0;
                result2 = 0;
            }
            MessageBox.Show($"{ticks1.Average().ToString()} Accord");
            MessageBox.Show($"{ticks2.Average().ToString()} VBA");
            MessageBox.Show($"Equal to {equalTo} decimal places.");
        }
        public void btnTestMMult_Click(IRibbonControl e)
        {
            Random rando = new Random();

            double[,] m1 = new double[5, 5];
            double[,] m2 = new double[5, 5];

            List <long> ticks1 = new List <long>();
            List <long> ticks2 = new List <long>();
            List <long> ticks3 = new List <long>();

            for (int i = 0; i < 100; i++)       //measure timing
            {
                for (int i2 = 0; i2 < m2.GetLength(0); i2++)
                {
                    for (int j = 0; j < m2.GetLength(1); j++)
                    {
                        m1[i2, j] = rando.NextDouble();
                        m2[i2, j] = rando.NextDouble();
                    }
                }
                DiagnosticsMenu.StartStopwatch();
                double[,] result1 = MatrixOps.MMult(m1, m2);
                DiagnosticsMenu.StopStopwatch(TimeUnit.ticks);
                ticks1.Add(DiagnosticsMenu.stopwatch.ElapsedTicks);
                DiagnosticsMenu.StartStopwatch();
                double[,] result2 = MatrixOps.Accord_MMult(m1, m2);
                DiagnosticsMenu.StopStopwatch(TimeUnit.ticks);
                ticks2.Add(DiagnosticsMenu.stopwatch.ElapsedTicks);
                DiagnosticsMenu.StartStopwatch();
                dynamic result3 = ThisAddIn.MyApp.WorksheetFunction.MMult(m1, ThisAddIn.MyApp.WorksheetFunction.Transpose(m2));
                DiagnosticsMenu.StopStopwatch(TimeUnit.ticks);
                ticks3.Add(DiagnosticsMenu.stopwatch.ElapsedTicks);
                //int places = TestEquality(result1, result2);
                //if (places < equalTo)
                //    equalTo = places;
                result1 = null;
                result2 = null;
                result3 = null;
            }
            MessageBox.Show($"{ticks1.Average().ToString()} Manual");
            MessageBox.Show($"{ticks2.Average().ToString()} Accord");
            MessageBox.Show($"{ticks3.Average().ToString()} VBA");

            double[,] vba_out = Utilities.Conversions.ConvertObjectArrayToDouble(ThisAddIn.MyApp.WorksheetFunction.MMult(m1, m2));
            double[,] man_out = MatrixOps.MMult(m1, m2);
            double[,] acc_out = MatrixOps.Accord_MMult(m1, m2);

            ThisAddIn.MyApp.ActiveSheet.Range("A1").Value      = "Manual";
            ThisAddIn.MyApp.ActiveSheet.Range("A2:E6").Value   = man_out;
            ThisAddIn.MyApp.ActiveSheet.Range("A7").Value      = "Accord";
            ThisAddIn.MyApp.ActiveSheet.Range("A8:E12").Value  = acc_out;
            ThisAddIn.MyApp.ActiveSheet.Range("A13").Value     = "VBA Function";
            ThisAddIn.MyApp.ActiveSheet.Range("A14:E18").Value = vba_out;

            ThisAddIn.MyApp.ActiveSheet.Range("G1").Value     = "M1";
            ThisAddIn.MyApp.ActiveSheet.Range("G2:K6").Value  = m1;
            ThisAddIn.MyApp.ActiveSheet.Range("G7").Value     = "M2";
            ThisAddIn.MyApp.ActiveSheet.Range("G8:K12").Value = m2;

            MessageBox.Show($"MAN v ACC Precision: {TestEquality(man_out, acc_out)}");
            MessageBox.Show($"MAN v VBA Precision: {TestEquality(man_out, vba_out)}");
            MessageBox.Show($"ACC v VBA Precision: {TestEquality(acc_out, vba_out)}");
        }