From f87cc6660b8e41527b7748dec129ccfe05b41176 Mon Sep 17 00:00:00 2001 From: Andrey Maltsev Date: Mon, 22 Oct 2018 20:10:34 +0300 Subject: [PATCH] v0.4 --- linear/Program.cs | 83 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/linear/Program.cs b/linear/Program.cs index f40962a..4ec40d7 100644 --- a/linear/Program.cs +++ b/linear/Program.cs @@ -12,10 +12,10 @@ namespace linear static void Main(string[] args) { Random rnd = new Random(); - int pointCount = 2; + int pCount = 2; int workCount = 3; - int[,] matrix = new int[workCount + 2, pointCount + 1]; + double[,] matrix = new double[workCount + 2, pCount + 1]; //for(int i = 0; i < workCount + 1; i++) //{ @@ -39,7 +39,7 @@ namespace linear for (int i = 0; i < workCount + 1; i++) { - for (int j = 0; j < pointCount + 1; j++) Write(matrix[i, j] + " "); + for (int j = 0; j < pCount + 1; j++) Write(matrix[i, j] + " "); WriteLine(); } WriteLine("\n\n"); @@ -75,11 +75,54 @@ namespace linear foreach (Point p in Points) WriteLine("{0:00.00} {1:00.00}", p.X, p.Y); Write("\n\n"); - WriteLine("{0} {1}", xMin, yMin); + WriteLine("{0:0.0} {1:0.0}\n\n", xMin, yMin); + int[] indexes = new int[3]; if(indexMinX != indexMinY) { - // Points.Add(new Point { X = Points[]}) + indexes[0] = indexMinX - 1; + indexes[1] = indexMinY - 1; + for (int i = 0; i < 3; i++) + if (i != indexes[0] && i != indexes[1]) indexes[2] = i; + + //WriteLine("index[2]= {0}", indexes[2]); + //WriteLine(indexMinX + " " + indexMinY); + + + Points.Add(Gaussian(ref matrix, indexes[0] , indexes[1])); + WriteLine("[{0:00.00} ;{1:00.00}] Линии: {2}", Points[Points.Count - 1].X, Points[Points.Count - 1].Y, Points[Points.Count - 1].Line); + WriteLine(Points.Count + "\n\n"); + + + Points.Add(Gaussian(ref matrix, indexes[0], indexes[2])); + WriteLine("[{0:00.00} ;{1:00.00}] Линии: {2}", Points[Points.Count - 1].X, Points[Points.Count - 1].Y, Points[Points.Count - 1].Line); + WriteLine(Points.Count + "\n\n"); + + + foreach (Point p in Points) WriteLine("{0} {1} {2}", p.X, p.Y, p.Line); // y = x , x =y + + + if (Points[Points.Count - 1].X < 0 || Points[Points.Count - 1].Y < 0) Points.RemoveAt(Points.Count - 1); + + if (Points[Points.Count - 2].X > Points[Points.Count - 1].X) + { + Points.RemoveAt(Points.Count - 1); + Points.Add(Gaussian(ref matrix, indexes[1], indexes[2])); + } + else { + + double tempQ = 0d; + for (int i= 1; i < 4; i++) + { + WriteLine("{0} {1} {2}", i, Points[Points.Count - i].X, Points[Points.Count - i].Y); + double t = Result(matrix, Points[Points.Count - i].X, Points[Points.Count - i].Y); + if (tempQ < t) tempQ = t; + } + + WriteLine(tempQ); + } + + } else @@ -95,6 +138,36 @@ namespace linear ReadKey(); } + // сумма выручки для точки x,y + public static double Result(double[,] matrix, double x, double y) + { + double res; + res = matrix[3, 0] * x + matrix[3, 1]*y; + return res; + } + + + // метод гауса для нахождения координаты пересечения + public static Point Gaussian(ref double[,] matrix, int line1, int line2) + { + Point p = new Point(); + double kof; + double tempX; + double tempY; + double tempRes; + kof = matrix[line1, 0] / matrix[line2, 0]; + tempX = matrix[line1, 0] - matrix[line2, 0] * kof; + tempY = matrix[line1, 1] - matrix[line2, 1] * kof; + tempRes = matrix[line1, 2] - matrix[line2, 2] * kof; + + WriteLine("{0:00.00} : [{1:00.00};{2:00.00}] = {3:00.00}", kof, tempX, tempY, tempRes); + if ((int)tempX != 0) throw new FormatException(); + p.Y = tempRes / tempY; + p.X = (matrix[line2, 2] - matrix[line2, 1] * p.Y) / matrix[line2, 0]; + p.Line = (line1 + 1) * 10 + line2 + 1; + + return p; + } public struct Point { public double X { get; set; }