public static MyMatrix generateAproxMatrix(int polynomialRank, ResultsFunction data)
        {
            int      rows    = data.x.Count;
            int      columns = 7 + 3 * (polynomialRank - 1);
            MyMatrix matrix  = new MyMatrix(rows, columns);

            for (int row = 0; row < rows; row++)
            {
                matrix[row, 0] = data.x[row];
                matrix[row, 1] = data.y[row];
            }
            for (int row = 0; row < rows; row++)
            {
                for (int col = 2; col <= 2 + 2 * polynomialRank; col++)
                {
                    matrix[row, col] = Math.Pow(data.x[row], col - 2);
                }
            }
            for (int row = 0; row < rows; row++)
            {
                for (int col = 3 + 2 * polynomialRank; col < columns; col++)
                {
                    matrix[row, col] = data.y[row] * Math.Pow(data.x[row], col - (3 + 2 * polynomialRank));
                }
            }
            return(matrix);
        }
        private static void launchZad4()
        {
            string          fileName       = "results2.txt";
            int             polynomialRank = 3;
            ResultsFunction results        = FileHelper.readResultsFromFile(fileName);
            MyMatrix        matrix         = MyMatrix.generateAproxMatrix(polynomialRank, results);
            //Console.Write(matrix.ToString());
            MyMatrix vector = MyMatrix.getVectorFromAproxMatrix(matrix);
            //Console.Write(vector.ToString());
            MyMatrix matrixForGauss = MyMatrix.createMatrixFromVector(polynomialRank, vector);
            //Console.Write(matrixForGauss);
            MyMatrix resultVector = MyMatrix.gauss(matrixForGauss, 1, false);

            Console.Write(resultVector);
        }
Beispiel #3
0
        public static ResultsFunction readResultsFromFile(string fileName)
        {
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("Could not open file " + fileName + " !");
            }
            string[]        data    = File.ReadAllLines(fileName);
            ResultsFunction results = new ResultsFunction();

            for (int i = 0; i < data.Length; i++)
            {
                string[] scanner = data[i].Split(' ');
                results.x.Add(Int32.Parse(scanner[0]));
                results.y.Add(Int32.Parse(scanner[1]));
            }
            return(results);
        }