Exemple #1
0
        //u'' + u = f; u(a) = u0 u(b) = u1
        public static void D2_B_bc(int SIZE, double a_border, double b_border,
                                   ICardinalStratagy calculate,
                                   double u0, double u1, FunctionLib.Function function)
        {
            int degree = 4;
            int N      = SIZE;
            int M      = N + degree - 2;
            int m      = degree - 2;

            Matrix U = new Matrix(m, M);



            double         h      = MyMath.Basic.GetStep(N, a_border, b_border);
            CardinalSpline spline = new CardinalSpline(calculate);

            Matrix D = (1d / Math.Pow(h, m)) * CardinalOperators.DerevetiveMatrix(degree, SIZE) + CardinalOperators.InterpolateConditionMatrix(degree, SIZE, calculate);

            //условие 1: (c,ksi(a)) = u0
            Vector ksi_a = spline.SplineVector(a_border, a_border, b_border, N, degree);
            //условие 1: (c,ksi(b)) = u1
            Vector ksi_b = spline.SplineVector(b_border, a_border, b_border, N, degree);

            for (int i = 0; i < M; i++)
            {
                U[0, i] = ksi_a[i];
                U[1, i] = ksi_b[i];
            }

            //-------------
            //Составляем линейную систему
            Matrix A = ConstructMatrix(D, U);

            //Составляем правую часть
            Vector b       = MyMath.Basic.GetVectorFunction(N, a_border, b_border, function);
            Vector y       = Matrix.Transpose(D) * b;
            Vector y_prime = new Vector(y.Length + m);

            y_prime[y.Length]     = u0;
            y_prime[y.Length + 1] = u1;

            for (int i = 0; i < y.Length; i++)
            {
                y_prime[i] = y[i];
            }

            Console.WriteLine("right part = " + y_prime);
            // Console.WriteLine(A);

            Vector x = Solver.BCG(A, y_prime, 0.0001d);

            Console.WriteLine("x = " + x);
            Vector c = x.SubVector(0, M);
            Vector f = spline.GetVectorFunction(N, a_border, b_border, c, h, degree);

            Console.WriteLine("f = " + f);
            f = 2 * spline.GetVectorFunction(10 * N, a_border, b_border, c, h, degree);
            b = MyMath.Basic.GetVectorFunction(10 * N, a_border, b_border, function);
            Console.WriteLine("||err|| = " + (f - b).Norm);
        }
        public static Vector GetSolutionTask1(Vector p, Matrix f, FunctionLib.Function phi,
                                              double nu, double L, double TIME,
                                              double aa, int N, int M)
        {
            double h   = MyMath.GetStep(N, 0d, L);
            double tau = MyMath.GetStep(M, 0d, TIME);
            Vector u0  = new Vector(N);
            Vector fu  = new Vector(N);

            for (int i = 0; i < N; i++)
            {
                u0[i] = phi(i * h);
            }

            for (int iter_t = 0; iter_t < M; iter_t++)
            {
                for (int i = 0; i < N; i++)
                {
                    fu[i] = f[iter_t, i];
                }
                u0 = SolveSliceTask1(u0, fu, p, nu, h, tau, aa, iter_t);
            }

            return(u0);
        }
        public static Matrix GetSolutionTask2(FunctionLib.Function y, Vector x_T,
                                              double nu, double L, double TIME,
                                              double aa, int N, int M)
        {
            double h   = MyMath.GetStep(N, 0d, L);
            double tau = MyMath.GetStep(M, 0d, TIME);
            Vector u0  = new Vector(N);
            Vector fu  = new Vector(N);
            Matrix KSI = new Matrix(M, N);

            for (int i = 0; i < N; i++)
            {
                u0[i]         = 2d * (x_T[i] - y(i * h));
                KSI[M - 1, i] = u0[i];
            }

            for (int iter_t = 1; iter_t < M; iter_t++)
            {
                for (int j = 0; j < N; j++)
                {
                    KSI[M - 1 - iter_t, j] = u0[j];
                }

                u0 = SolveSliceTask2(u0, nu, h, tau, aa);
            }

            return(KSI);
        }
Exemple #4
0
        public OptimalManaging(double LengthVal, double TimeVal,
                               double sq_a, double Nu, int TIME_M, int LEN_N,
                               double eps1, double eps2,
                               FunctionLib.Function distrib_y,
                               FunctionLib.Function env_temperature_p,
                               FunctionLib.Function temperature0,
                               FunctionLib.Function2d temperature_sourses,
                               double pmin, double pmax, double INT_R)
        {
            ITERATION = 0;
            L         = LengthVal;
            T         = TimeVal;
            aa        = sq_a;
            nu        = Nu;
            R         = INT_R;

            TIME_SIZE = TIME_M;
            GRID_SIZE = LEN_N;

            EPS1  = eps1;
            EPS2  = eps2;
            P_MAX = pmax;
            P_MIN = pmin;
            double C0 = Get_C0();
            double C1 = Get_C1();

            LIP = Math.Sqrt(2d * C0 * C1);

            manage_p = new Vector(TIME_SIZE);

            y   = distrib_y;
            p   = env_temperature_p;
            phi = temperature0;
            f   = temperature_sourses;

            alpha_old = 5d;

            double tau = MyMath.GetStep(TIME_SIZE, 0d, T);
            double h   = MyMath.GetStep(GRID_SIZE, 0d, L);

            for (int i = 0; i < TIME_SIZE; i++)
            {
                manage_p[i] = p(tau * i);
            }

            manage_f = new Matrix(TIME_SIZE, GRID_SIZE);
            for (int i = 0; i < TIME_SIZE; i++)
            {
                for (int j = 0; j < GRID_SIZE; j++)
                {
                    manage_f[i, j] = f(h * j, tau * i);
                }
            }

            //Vector temp = MyMath.GetVectorFunction(GRID_SIZE, 0d, LengthVal, y);
            //R = MyMath.TrapezoidMethod(temp, h);
        }
Exemple #5
0
            public static Vector GetConvolutionVector(FunctionLib.Function f, FunctionLib.Function g, int GridSize, double a, double b)
            {
                Vector fg   = new Vector(GridSize);
                Grid   grid = new Grid(GridSize, a, b);

                for (int i = 4; i < GridSize; i++)
                {
                    fg[i] = Convolution(grid[i], f, g, grid);
                }

                return(fg);
            }
        public OptimalManaging(double LengthVal, double TimeVal,
                               double sq_a, double Nu, int TIME_M, int LEN_N,
                               double eps1, double eps2,
                               FunctionLib.Function distrib_y,
                               FunctionLib.Function env_temperature_p,
                               FunctionLib.Function temperature0,
                               FunctionLib.Function2d temperature_sourses)
        {
            ITERATION = 0;
            L         = LengthVal;
            T         = TimeVal;
            aa        = sq_a;
            nu        = Nu;


            TIME_SIZE = TIME_M;
            GRID_SIZE = LEN_N;

            EPS1  = eps1;
            EPS2  = eps2;
            P_MAX = 1000;
            P_MIN = -1000;
            double C0 = Get_C0();
            double C1 = Get_C1();

            LIP      = Math.Sqrt(2d * C0 * C1);
            R        = 10;
            manage_p = new Vector(TIME_SIZE);

            y   = distrib_y;
            p   = env_temperature_p;
            phi = temperature0;
            f   = temperature_sourses;

            double tau = MyMath.Basic.GetStep(TIME_SIZE, 0d, T);
            double h   = MyMath.Basic.GetStep(GRID_SIZE, 0d, L);

            for (int i = 0; i < TIME_SIZE; i++)
            {
                manage_p[i] = p(tau * i);
            }
            manage_f = new Matrix(TIME_SIZE, GRID_SIZE);
            for (int i = 0; i < TIME_SIZE; i++)
            {
                for (int j = 0; j < GRID_SIZE; j++)
                {
                    manage_f[i, j] = f(h * j, tau * i);
                }
            }
        }
Exemple #7
0
            public static double Convolution(double x, FunctionLib.Function f, FunctionLib.Function g, int GridSize, double a)
            {
                Vector grid = Vector.CreateUniformGrid(GridSize, a, x);
                Vector fg   = new Vector(GridSize);
                double h    = grid[1] - grid[0];

                for (int i = 0; i < GridSize; i++)
                {
                    fg[i] = f(grid[i]) * g(x - grid[i]);
                }


                return(Integrate.Simpson(fg.ToArray, h));
            }
Exemple #8
0
            public static double Convolution(double x, FunctionLib.Function f, FunctionLib.Function g, Grid grid)
            {
                int GridSize = grid.Count;

                Vector fg = new Vector(GridSize);
                double h  = grid[1] - grid[0];

                for (int i = 0; i < GridSize; i++)
                {
                    fg[i] = f(grid[i]) * g(x - grid[i]);
                }


                return(Integrate.Simpson(fg.ToArray, h));
            }
Exemple #9
0
        //Первая тестовая функция для решения дифференциального уравнения второго порядка
        public static void SolveSecondDerevitiveEquation(int GridSize, double a_border, double b_border,
                                                         ICardinalStratagy calculate,
                                                         double u0, double u1, FunctionLib.Function function)
        {
            int N      = GridSize;
            int degree = 4;

            double         h      = MyMath.Basic.GetStep(N, a_border, b_border);
            CardinalSpline spline = new CardinalSpline(calculate);

            Vector f  = MyMath.Basic.GetVectorFunction(N, a_border, b_border, function);
            Matrix D  = CardinalDifferentialEquation.SecondDirevetive(N);
            Matrix DD = D * Matrix.Transpose(D);
            //   Console.WriteLine(DD);
            Matrix A = (1d / (h * h)) * DD;

            Console.WriteLine(D * f);
            Vector Dy = D * f;
            Vector b  = new Vector(N + 4);

            for (int i = 0; i < N + 2; i++)
            {
                b[i] = Dy[i];
            }
            b[N + 2] = u0;
            b[N + 3] = u1;
            Console.WriteLine("b = " + b);
            Matrix B = new Matrix(N + 4);

            for (int i = 0; i < N + 2; i++)
            {
                for (int j = 0; j < N + 2; j++)
                {
                    B[i, j] = A[i, j];
                }
            }
            for (int i = 0; i < N + 2; i++)
            {
                B[N + 2, i] = calculate.Cardinal(degree, a_border, a_border + (i - degree + 1) * h, h);
                B[N + 3, i] = calculate.Cardinal(degree, b_border, a_border + (i - degree + 1) * h, h);

                B[i, N + 2] = -B[N + 2, i];
                B[i, N + 3] = -B[N + 3, i];
            }
        }
Exemple #10
0
        public void MainStartOfCardinalSolverSystem()
        {
            int    N = 25;
            double a = 0;
            double b = 3.14;

            FunctionLib.Function f = (t) => 0.5 * Math.Sin(t);

            for (int i = 5; i <= 5; i++)
            {
                MyMathLib.Spline.CardinalFiniteMethod.CardinalSolver.D4_B_bc(31, a, b
                                                                             , new DividedDifferencesStategy(),
                                                                             0, FunctionLib.sin(b),
                                                                             0, -FunctionLib.sin(b),
                                                                             f);
                //System.Diagnostics.Debug.WriteLine("===================");
                Console.WriteLine("=========================================");
            }
        }
        public static void MIN_Interpolation_Test(FunctionLib.Function func, ref Vector x, ref Vector expect, ref Vector actual, int degree, int Size, double a_border, double b_border)
        {
            //setup

            double a        = a_border;
            double b        = b_border;
            int    GridSize = Size;
            int    deg      = degree;
            Vector grid     = Vector.CreateUniformGrid(GridSize, a, b);
            double h        = MyMath.Basic.GetStep(GridSize, a, b);
            Vector y        = MyMath.Basic.GetVectorFunction(GridSize, a, b, func);
            Grid   tau      = new Grid(deg, grid, grid[0], grid.Last, true);

            tau.ToPeriodiclineGrid();
            //run


            Vector min_c = Spline.InterpolateExperiment.Interpolate_By_CardinalSpline(y, deg, h);

            // Console.WriteLine("c = " + c);
            Console.WriteLine("min_c = " + min_c);
            Console.WriteLine("Степень сплайна = " + deg);
            //compare
            int N = 10 * GridSize;

            expect = MyMath.Basic.GetVectorFunction(N - 1, a, b, func);
            CardinalSpline spline = new CardinalSpline();

            actual = spline.GetVectorFunction(N - 1, a, b, min_c, h, deg);
            x      = Vector.CreateUniformGrid(N - 1, a, b);
            Vector bf = spline.GetVectorFunction(GridSize, a, b, min_c, h, deg);


            double result        = (expect - actual).Norm;
            double interpolation = (y - bf).Norm;


            Console.WriteLine("значение f(x) = " + y.ToString());
            Console.WriteLine("значение bf(x) = " + bf.ToString());
            Console.WriteLine("||c|| = " + min_c.Norm.ToString("0.000000"));
            Console.WriteLine("||f - spline|| = " + result.ToString("0.000000"));
        }
Exemple #12
0
        public static Vector GetVectorFunction(int GridSize, double a_border, double b_border, FunctionLib.Function F)
        {
            Vector f = new Vector(GridSize);
            double h = GetStep(GridSize, a_border, b_border);

            for (int i = 0; i < GridSize; i++)
            {
                f[i] = F(a_border + i * h);
            }
            return(f);
        }