Пример #1
0
        public static void CorrectEigenvectorsTest(double[] a)
        {
            var matrix       = SquareMatrixHelper.SquareMatrix(a);
            var eigenvalues  = matrix.Eigenvalues();
            var eigenvectors = matrix.GetEigenvectors();

            Assert.AreEqual(matrix * eigenvectors.Column(0), eigenvalues[0].Re * eigenvectors.Column(0));
            if ((eigenvalues[0].Re - eigenvalues[1].Re).IsZero() && matrix.GetGeometricMultiplicity(eigenvalues[0].Re) == 1)
            {
                Assert.AreNotEqual(matrix * eigenvectors.Column(1), eigenvalues[1].Re * eigenvectors.Column(1));
            }
            else
            {
                Assert.AreEqual(matrix * eigenvectors.Column(1), eigenvalues[1].Re * eigenvectors.Column(1));
            }
        }
    public static List <FullMatrixData> ParseSquareMatrix(string inputMatrix, string fileName)
    {
        List <char>     separators = SquareMatrixHelper.FindNumberSeparators(inputMatrix);
        char            separator  = SquareMatrixHelper.SelectPopularSeparator(separators);
        string          delimiter  = SquareMatrixHelper.GetDelimiter(separator, inputMatrix);
        List <string[]> matrixData = SquareMatrixHelper.GetMatrixData(inputMatrix, delimiter);
        List <string>   matrixHat  = SquareMatrixHelper.GetMatrixHat(matrixData);

        if (matrixHat != null)
        {
            matrixData = SquareMatrixHelper.CutMatrixHat(matrixData, matrixHat);
        }
        int startLine = SquareMatrixHelper.GetStartLine(matrixData, delimiter, inputMatrix);
        List <ConnectionsJson> connections = SquareMatrixHelper.MatrixConnections(matrixData);

        List <PrimaryGraph.Verticle> graph = new List <PrimaryGraph.Verticle>();
        var numberGroups = connections.GroupBy(i => i.from);

        foreach (var grp in numberGroups)
        {
            PrimaryGraph.Verticle v = new PrimaryGraph.Verticle();
            v.verticle_id = (grp.Key + 1).ToString();
            if (matrixHat != null)
            {
                v.verticle = matrixHat[grp.Key];
            }
            else
            {
                v.verticle = (grp.Key + 1).ToString();
            }
            List <PrimaryGraph.Connections> cons = new List <PrimaryGraph.Connections>();
            foreach (ConnectionsJson connection in connections)
            {
                if (connection.value > 0 && grp.Key == connection.from)
                {
                    PrimaryGraph.Connections c = new PrimaryGraph.Connections();
                    c.connectedTo = (connection.to + 1).ToString();
                    c.strength    = connection.value;
                    cons.Add(c);
                }
            }
            v.connections = cons;
            graph.Add(v);
        }

        List <GenerationRules> generationRules = new List <GenerationRules>();

        generationRules.Add(new GenerationRules {
            delimiter = delimiter, matrixAtLine = startLine, separator = separator.ToString(), type = "square", notation = ""
        });
        string yamlRules = Helper.CollectGenerationRulesToYAML(generationRules);

        List <FullMatrixData> fullMatrixData = new List <FullMatrixData>();
        MatrixJson            jsonMatrix     = SquareMatrixHelper.MatrixToJson(matrixData, fileName);

        fullMatrixData.Add(new FullMatrixData {
            delimiter = delimiter, separator = separator, matrixData = matrixData, startLine = startLine, matrixJson = jsonMatrix, graph = graph, generationRules = generationRules, yamlRules = yamlRules
        });

        return(fullMatrixData);
    }
        public static void CorrectMatrixExponentialCalculations(double[] actualEntries, double[] expectedExpMEntries)
        {
            var expectedExpM = SquareMatrixHelper.ExpM(SquareMatrixHelper.SquareMatrix(actualEntries))(1.0);

            Assert.AreEqual(expectedExpMEntries, GetOriginEntries(expectedExpM));
        }
Пример #4
0
 public static double[] CorrectEigenvaluesTest(double[] a)
 {
     return(GetEigenvaluesArray(SquareMatrixHelper.SquareMatrix(a).Eigenvalues()));
 }