Exemplo n.º 1
0
        private List <double> GetSolutionTest2(double n, double h, double ksi)
        {
            List <double> solution = new List <double>();
            double        C1, C2, C3, C4;
            double        A1, A2, B1, B2;
            double        A11, A12, A21, A22;
            double        val1, val2;
            MyFunctions   myFunc = new MyFunctions();

            A1   = myFunc.q1(ksi) / myFunc.k1(ksi);
            A2   = myFunc.q2(ksi) / myFunc.k2(ksi);
            B1   = -myFunc.f1(ksi) / myFunc.q1(ksi);
            B2   = -myFunc.f2(ksi) / myFunc.q2(ksi);
            A11  = -(Math.Exp(Math.Pow(A1, 0.5) * ksi) - Math.Exp(-Math.Pow(A1, 0.5) * ksi));
            A12  = Math.Exp(-2 * Math.Pow(A2, 0.5) + Math.Pow(A2, 0.5) * ksi) - Math.Exp(-Math.Pow(A2, 0.5) * ksi);
            A21  = -myFunc.k1(ksi) * Math.Pow(A1, 0.5) * (Math.Exp(Math.Pow(A1, 0.5) * ksi) + Math.Exp(-Math.Pow(A1, 0.5) * ksi));
            A22  = myFunc.k2(ksi) * Math.Pow(A2, 0.5) * (Math.Exp(-2 * Math.Pow(A2, 0.5) + Math.Pow(A2, 0.5) * ksi) + Math.Exp(-Math.Pow(A2, 0.5) * ksi));
            val1 = (1 + B2) * Math.Exp(Math.Pow(A2, 0.5) * ksi - Math.Pow(A2, 0.5)) - B2 + B1 * (1 - Math.Exp(Math.Pow(A1, 0.5) * ksi));
            val2 = -myFunc.k1(ksi) * Math.Pow(A1, 0.5) * B1 * Math.Exp(Math.Pow(A1, 0.5) * ksi) + myFunc.k2(ksi) * Math.Pow(A2, 0.5) * (1 + B2) * Math.Exp(Math.Pow(A2, 0.5) * ksi - Math.Pow(A2, 0.5));
            A12  = A12 / A11;
            val1 = val1 / A11;
            A22  = A22 / A21 - A12;
            val2 = val2 / A21 - val1;
            val2 = val2 / A22;
            val1 = val1 - A12 * val2;
            C2   = val1;
            C4   = val2;
            C1   = B1 - C2;
            C3   = (1 + B2 - C4 * Math.Exp(-Math.Pow(A2, 0.5))) * Math.Exp(-Math.Pow(A2, 0.5));
            for (int i = 0; i < n + 1; i++)
            {
                if (ksi > h * i)
                {
                    solution.Add(C1 * Math.Exp(Math.Pow(A1, 0.5) * h * i) + C2 * Math.Exp(-Math.Pow(A1, 0.5) * h * i) - B1);
                }
                else
                {
                    solution.Add(C3 * Math.Exp(Math.Pow(A2, 0.5) * h * i) + C4 * Math.Exp(-Math.Pow(A2, 0.5) * h * i) - B2);
                }
            }
            return(solution);
        }
Exemplo n.º 2
0
        public StructForMainSolution MainSolution(int n, double x0, double xn, double ksi)
        {
            StructForMainSolution structForMain = new StructForMainSolution();

            structForMain.chart_pointV     = new ChartPoint();
            structForMain.chart_pointV.x   = new List <double>();
            structForMain.chart_pointV.Vx  = new List <double>();
            structForMain.chart_pointV2    = new ChartPoint();
            structForMain.chart_pointV2.x  = new List <double>();
            structForMain.chart_pointV2.Vx = new List <double>();
            double[]    k             = new double[n + 1];
            double[]    k2            = new double[2 * n + 1];
            double[]    f             = new double[n];
            double[]    f2            = new double[2 * n + 1];
            double[]    q             = new double[n];
            double[]    q2            = new double[2 * n + 1];
            double[]    diagonal1     = new double[n - 1];
            double[]    diagonal1_2   = new double[2 * n - 1];
            double[]    diagonal2     = new double[n];
            double[]    diagonal2_2   = new double[2 * n];
            double[]    diagonal3     = new double[n - 1];
            double[]    diagonal3_2   = new double[2 * n - 1];
            double[]    right_column  = new double[n];
            double[]    right_column2 = new double[2 * n];
            double      h             = (xn - x0) / n;
            double      h2            = h / 2;
            MyFunctions myFunc        = new MyFunctions();

            for (int i = 0; i < n + 1; ++i)
            {
                structForMain.chart_pointV.x.Add(i * h);
            }

            for (int i = 0; i < 2 * n + 1; ++i)
            {
                structForMain.chart_pointV2.x.Add(i * h2);
            }

            for (int i = 1; i < n; ++i)
            {
                if (ksi >= (structForMain.chart_pointV.x[i] + 0.5 * h))
                {
                    f[i] = myFunc.f1(structForMain.chart_pointV.x[i]);
                    q[i] = myFunc.q1(structForMain.chart_pointV.x[i]);
                }
                else if (ksi <= (structForMain.chart_pointV.x[i] - 0.5 * h))
                {
                    f[i] = myFunc.f2(structForMain.chart_pointV.x[i]);
                    q[i] = myFunc.q2(structForMain.chart_pointV.x[i]);
                }
                else
                {
                    f[i] = n * ((ksi - (structForMain.chart_pointV.x[i] - 0.5 * h)) * myFunc.f1(0.5 * ((structForMain.chart_pointV.x[i] - 0.5 * h) + ksi)) + ((structForMain.chart_pointV.x[i] + 0.5 * h) - ksi) * myFunc.f2(0.5 * (ksi + (structForMain.chart_pointV.x[i] + 0.5 * h))));
                    q[i] = n * ((ksi - (structForMain.chart_pointV.x[i] - 0.5 * h)) * myFunc.q1(0.5 * (ksi + (structForMain.chart_pointV.x[i] - 0.5 * h))) + ((structForMain.chart_pointV.x[i] + 0.5 * h) - ksi) * myFunc.q2(0.5 * ((structForMain.chart_pointV.x[i] + 0.5 * h) + ksi)));
                }


                if (ksi >= structForMain.chart_pointV.x[i])
                {
                    k[i] = 2 * myFunc.k1(structForMain.chart_pointV.x[i]) * myFunc.k1(structForMain.chart_pointV.x[i - 1]) / (myFunc.k1(structForMain.chart_pointV.x[i - 1]) + myFunc.k1(structForMain.chart_pointV.x[i]));
                }
                else if (ksi <= structForMain.chart_pointV.x[i - 1])
                {
                    k[i] = 2 * myFunc.k2(structForMain.chart_pointV.x[i - 1]) * myFunc.k2(structForMain.chart_pointV.x[i]) / (myFunc.k2(structForMain.chart_pointV.x[i - 1]) + myFunc.k2(structForMain.chart_pointV.x[i]));
                }
                else
                {
                    k[i] = 2 * h * myFunc.k1(structForMain.chart_pointV.x[i - 1]) * myFunc.k1(ksi) * myFunc.k2(ksi) * myFunc.k2(structForMain.chart_pointV.x[i]) / ((ksi - structForMain.chart_pointV.x[i - 1]) * (myFunc.k1(ksi) + myFunc.k1(structForMain.chart_pointV.x[i - 1])) * myFunc.k2(ksi) * myFunc.k2(structForMain.chart_pointV.x[i]) + (structForMain.chart_pointV.x[i] - ksi) * (myFunc.k2(structForMain.chart_pointV.x[i]) + myFunc.k2(ksi)) * myFunc.k1(structForMain.chart_pointV.x[i - 1]) * myFunc.k1(ksi));
                }
            }
            k[n] = 2 * myFunc.k2(structForMain.chart_pointV.x[(int)n]) * myFunc.k2(structForMain.chart_pointV.x[n - 1]) / (myFunc.k2(structForMain.chart_pointV.x[n - 1]) + myFunc.k2(structForMain.chart_pointV.x[(int)n]));

            structForMain.chart_pointV.Vx.Add(x0);

            for (int i = 1; i < 2 * n; ++i)
            {
                if (ksi >= (structForMain.chart_pointV2.x[i] + 0.5 * h2))
                {
                    f2[i] = myFunc.f1(structForMain.chart_pointV2.x[i]);
                    q2[i] = myFunc.q1(structForMain.chart_pointV2.x[i]);
                }
                else if (ksi <= (structForMain.chart_pointV2.x[i] - 0.5 * h2))
                {
                    f2[i] = myFunc.f2(structForMain.chart_pointV2.x[i]);
                    q2[i] = myFunc.q2(structForMain.chart_pointV2.x[i]);
                }
                else
                {
                    f2[i] = 2 * n * ((ksi - (structForMain.chart_pointV2.x[i] - 0.5 * h2)) * myFunc.f1(0.5 * ((structForMain.chart_pointV2.x[i] - 0.5 * h2) + ksi)) + ((structForMain.chart_pointV2.x[i] + 0.5 * h2) - ksi) * myFunc.f2(0.5 * (ksi + (structForMain.chart_pointV2.x[i] + 0.5 * h2))));
                    q2[i] = 2 * n * ((ksi - (structForMain.chart_pointV2.x[i] - 0.5 * h2)) * myFunc.q1(0.5 * (ksi + (structForMain.chart_pointV2.x[i] - 0.5 * h2))) + ((structForMain.chart_pointV2.x[i] + 0.5 * h2) - ksi) * myFunc.q2(0.5 * ((structForMain.chart_pointV2.x[i] + 0.5 * h2) + ksi)));
                }


                if (ksi >= structForMain.chart_pointV2.x[i])
                {
                    k2[i] = 2 * myFunc.k1(structForMain.chart_pointV2.x[i]) * myFunc.k1(structForMain.chart_pointV2.x[i - 1]) / (myFunc.k1(structForMain.chart_pointV2.x[i - 1]) + myFunc.k1(structForMain.chart_pointV2.x[i]));
                }
                else if (ksi <= structForMain.chart_pointV2.x[i - 1])
                {
                    k2[i] = 2 * myFunc.k2(structForMain.chart_pointV2.x[i - 1]) * myFunc.k2(structForMain.chart_pointV2.x[i]) / (myFunc.k2(structForMain.chart_pointV2.x[i - 1]) + myFunc.k2(structForMain.chart_pointV2.x[i]));
                }
                else
                {
                    k2[i] = 2 * h2 * myFunc.k1(structForMain.chart_pointV2.x[i - 1]) * myFunc.k1(ksi) * myFunc.k2(ksi) * myFunc.k2(structForMain.chart_pointV2.x[i]) / ((ksi - structForMain.chart_pointV2.x[i - 1]) * (myFunc.k1(ksi) + myFunc.k1(structForMain.chart_pointV2.x[i - 1])) * myFunc.k2(ksi) * myFunc.k2(structForMain.chart_pointV2.x[i]) + (structForMain.chart_pointV2.x[i] - ksi) * (myFunc.k2(structForMain.chart_pointV2.x[i]) + myFunc.k2(ksi)) * myFunc.k1(structForMain.chart_pointV2.x[i - 1]) * myFunc.k1(ksi));
                }
            }
            k2[2 * n] = 2 * myFunc.k2(structForMain.chart_pointV2.x[2 * n]) * myFunc.k2(structForMain.chart_pointV2.x[2 * n - 1]) / (myFunc.k2(structForMain.chart_pointV2.x[2 * n - 1]) + myFunc.k2(structForMain.chart_pointV2.x[2 * n]));
            structForMain.chart_pointV2.Vx.Add(x0);
            for (int i = 1; i < n - 1; ++i)
            {
                diagonal1[i] = k[i + 1] * n * n;
                diagonal2[i] = -(n * n * (k[i] + k[i + 1]) + q[i]);
                diagonal3[i] = k[i + 1] * n * n;
            }
            diagonal2[(int)n - 1] = -(n * n * (k[n - 1] + k[n]) + q[n - 1]);

            for (int i = 1; i < n; i++)
            {
                right_column[i] = -f[i];
            }
            right_column[1]     -= x0 * k[1] * n * n;
            right_column[n - 1] -= xn * k[n] * n * n;
            double[] solutionForV = Sweep(diagonal1, diagonal2, diagonal3, right_column);
            for (int i = 1; i < n; ++i)
            {
                structForMain.chart_pointV.Vx.Add(solutionForV[i - 1]);
            }
            for (int i = 1; i < 2 * n - 1; ++i)
            {
                diagonal1_2[i] = k2[i + 1] * n * n * 4;
                diagonal2_2[i] = -(4 * n * n * (k2[i] + k2[i + 1]) + q2[i]);
                diagonal3_2[i] = k2[i + 1] * n * n * 4;
            }
            diagonal2_2[2 * n - 1] = -(4 * n * n * (k2[2 * n - 1] + k2[2 * n]) + q2[2 * n - 1]);

            for (int i = 1; i < 2 * n; i++)
            {
                right_column2[i] = -f2[i];
            }
            right_column2[1]         -= x0 * k2[1] * n * n * 4;
            right_column2[2 * n - 1] -= xn * k2[2 * n] * n * n * 4;
            double[] solutionForV2 = Sweep(diagonal1_2, diagonal2_2, diagonal3_2, right_column2);
            for (int i = 1; i < 2 * n; ++i)
            {
                structForMain.chart_pointV2.Vx.Add(solutionForV2[i - 1]);
            }
            structForMain.chart_pointV.Vx.Add(xn);
            structForMain.chart_pointV2.Vx.Add(xn);
            return(structForMain);
        }
Exemplo n.º 3
0
        public ChartPoint SolutionsTest2(int n, double x0, double xn, double ksi)
        {
            ChartPoint chart_point = new ChartPoint();

            chart_point.x  = new List <double>();
            chart_point.y  = new List <double>();
            chart_point.Vx = new List <double>();
            double[]    k            = new double[n + 1];
            double[]    f            = new double[n];
            double[]    q            = new double[n];
            double[]    diagonal1    = new double[n - 1];
            double[]    diagonal2    = new double[n];
            double[]    diagonal3    = new double[n - 1];
            double[]    right_column = new double[n];
            MyFunctions myFunc       = new MyFunctions();
            double      h            = (xn - x0) / n;

            for (int i = 0; i < n + 1; i++)
            {
                chart_point.x.Add(i * h);
            }
            chart_point.y = GetSolutionTest2(n, h, ksi);
            for (int i = 1; i < n; ++i)
            {
                if (ksi >= (chart_point.x[i]) + 0.5 * h)
                {
                    f[i] = myFunc.f1(ksi);
                    q[i] = myFunc.q1(ksi);
                }
                else if (ksi <= (chart_point.x[i] - 0.5 * h))
                {
                    f[i] = myFunc.f2(ksi);
                    q[i] = myFunc.q2(ksi);
                }
                else
                {
                    f[i] = n * ((ksi - (chart_point.x[i] - 0.5 * h)) * myFunc.f1(ksi) + ((chart_point.x[i] + 0.5 * h) - ksi) * myFunc.f2(ksi));
                    q[i] = n * ((ksi - (chart_point.x[i] - 0.5 * h)) * myFunc.q1(ksi) + ((chart_point.x[i] + 0.5 * h) - ksi) * myFunc.q2(ksi));
                }

                if (ksi >= chart_point.x[i])
                {
                    k[i] = myFunc.k1(ksi);
                }
                else if (ksi <= (chart_point.x[i - 1]))
                {
                    k[i] = myFunc.k2(ksi);
                }
                else
                {
                    k[i] = 2 * h * myFunc.k1(ksi) * myFunc.k1(ksi) * myFunc.k2(ksi) * myFunc.k2(ksi) / ((ksi - chart_point.x[i - 1]) * (myFunc.k1(ksi) + myFunc.k1(ksi)) * myFunc.k2(ksi) * myFunc.k2(ksi) + (chart_point.x[i] - ksi) * (myFunc.k2(ksi) + myFunc.k2(ksi)) * myFunc.k1(ksi) * myFunc.k1(ksi));
                }
            }
            k[(int)n] = myFunc.k2(ksi);
            chart_point.Vx.Add(x0);

            for (int i = 1; i < n - 1; ++i)
            {
                diagonal1[i] = k[i + 1] * n * n;
                diagonal2[i] = -(n * n * (k[i] + k[i + 1]) + q[i]);
                diagonal3[i] = k[i + 1] * n * n;
            }
            diagonal2[n - 1] = -(n * n * (k[n - 1] + k[n]) + q[n - 1]);

            for (int i = 1; i < n; i++)
            {
                right_column[i] = -f[i];
            }
            right_column[1]     -= x0 * k[1] * n * n;
            right_column[n - 1] -= xn * k[n] * n * n;
            double[] sweep_result = Sweep(diagonal1, diagonal2, diagonal3, right_column);
            for (int i = 0; i < sweep_result.Length; i++)
            {
                chart_point.Vx.Add(sweep_result[i]);
            }
            chart_point.Vx.Add(xn);
            return(chart_point);
        }