Example #1
0
        static void SolveTask(float step)
        {
            float b     = 10f;
            float y0    = 1f;
            int   order = (int)(b / step) + 1;

            float[] euler = EulerMethod.Solve(TaskFunction, y0, b, step);
            float[] gear  = GearsMethod.Solve(TaskFunction, 3, b, y0, step);
            float[] real  = new float[order];
            for (int i = 0; i < order; i++)
            {
                real[i] = RealTaskFunction(i * step);
            }
            using (var file = File.OpenWrite($"task_equation_results_{step}.csv"))
            {
                using (var writer = new StreamWriter(file))
                {
                    writer.WriteLine("x,euler,gear,actual,eulerError,gearError");
                    for (int i = 0; i < order; i++)
                    {
                        writer.WriteLine($"{i * step},{euler[i]},{gear[i]},{real[i]},{Math.Abs(euler[i] - real[i])},{Math.Abs(gear[i] - real[i])}");
                    }
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            EulerMethod euler = new EulerMethod(1, 3, 10, 1);

            // Method4 method4 = new Method4(1, 3, 10, 1);

            Console.ReadLine();
        }
Example #3
0
        public int DecryptC1C2()
        {
            int key = ModuloBase.Power(C1, C2, q);

            Console.WriteLine("Key : " + key);
            int Mdecrypt = (C2 * EulerMethod.ModuloInverse(key, q)) % q;

            return(Mdecrypt);
        }
Example #4
0
        public static void Main(string[] args)
        {
            Mono.
            Console.WriteLine("Hello World!");
            var equation = new Equation();

            if (EulerMethod.Solve(equation, 0.1, 10, 0, 1))
            {
                equation.ShowInConsole();
            }
        }
Example #5
0
        public static bool isCanNguyenThuy(int a, int n)
        {
            int phiN = EulerMethod.phi(n);

            if (1 == ModuloBase.Power(a, phiN, n))
            {
                for (int i = 1; i < phiN; i++)
                {
                    if (phiN % i == 0)
                    {
                        if (1 == ModuloBase.Power(a, i, n))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            return(false);
        }
        public void SolveExplicit_Compare_With_Example()
        {
            //Arrange
            Equation func = delegate(double x, double[] y)
            {
                return(-y[0] + x * x + 2 * x + 2);
            };

            ODE[] ode = new ODE[] { new ODE(func, 0, 2) };

            double a = 0;
            double b = 1;
            int    N = 4;
            double h = (b - a) / N;

            double[][] expected = new double[N + 1][];
            double     step     = a;

            expected[0] = new double[] { 2 };
            expected[1] = new double[] { 2 };
            expected[2] = new double[] { 2.140625 };
            expected[3] = new double[] { 2.41796875 };
            expected[4] = new double[] { 2.8291015625 };

            //Act
            double[][] actual = EulerMethod.SolveExplicit(ode, a, b, N);

            //Assert
            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j < ode.Length; j++)
                {
                    Assert.AreEqual(expected[i][j], actual[i][j]);
                }
            }
        }
Example #7
0
 public static void TestLinearEquation()
 {
     Func <double, double, double> exampleEquation = (x, _) => x;
     List <double[]> points = EulerMethod.EulerFull(0, 4, 0.001, 0, exampleEquation);
     var             yEnd   = points[^ 1][1];