コード例 #1
0
        /// <summary>
        /// Casts an arc (curvature) of a function over a length.
        /// </summary>
        /// <param name="f">The function.</param>
        /// <param name="a">The arc length.</param>
        public static double Curvature(Function f, double a)
        {
            Differentiation ddiff = DdPointCenter(); // could be parameters
            Differentiation diff  = D5PointCenter();

            return(ddiff(f, a) / Math.Pow(1 + Math.Pow(diff(f, a), 2), 1.5));
        }
コード例 #2
0
        public Differentiation CreateOrUpdate(Differentiation differentiation)
        {
            Guard.Against.Null(differentiation, nameof(differentiation));

            var diff = _repository.GetById <Differentiation>(differentiation.Id);

            if (diff != null)
            {
                if (!string.IsNullOrEmpty(differentiation.Left))
                {
                    diff.setLeft(differentiation.Left);
                }
                else if (!string.IsNullOrEmpty(differentiation.Right))
                {
                    diff.setRight(differentiation.Right);
                }

                _repository.Update(diff);
            }
            else
            {
                diff = _repository.Add <Differentiation>(differentiation);
            }
            return(diff);
        }
コード例 #3
0
        public void Create_with_valid_parameters_must_succeed(int id, string left, string right)
        {
            //Arrange & Act
            var diff = new Differentiation(id, left, right);

            //Assert
            Assert.NotNull(diff);
        }
コード例 #4
0
        /// <summary>
        /// Point-center double differentiation method.
        /// </summary>
        public static Differentiation DdPointCenter()
        {
            const double h = 0.002;

            Differentiation ddifferentiation = (f, x) =>
                                               (-f(x + 2 * h) + 16 * f(x + h) - 30 * f(x) + 16 * f(x - h) - f(x - 2 * h)) / (12 * h * h);

            return(ddifferentiation);
        }
コード例 #5
0
        /// <summary>
        /// Method of finite forward difference for the boundary value of the numerical solution.
        /// </summary>
        /// <returns></returns>
        public static Differentiation D5PointForward()
        {
            const double h = 0.0005;

            Differentiation differentiation = (f, x) =>
                                              (-3 * f(x + 4 * h) + 16 * f(x + 3 * h) - 36 * f(x + 2 * h) + 48 * f(x + h) - 25 * f(x)) / (12 * h);

            return(differentiation);
        }
コード例 #6
0
        /// <summary>
        /// Method of finite central difference for the boundary value of the numerical solution.
        /// </summary>
        /// <returns></returns>
        public static Differentiation D5PointCenter()
        {
            const double h = 0.0005;

            Differentiation differentiation = (f, x) =>
                                              (-f(x + 2 * h) + 8 * f(x + h) - 8 * f(x - h) + f(x - 2 * h)) / (12 * h);

            return(differentiation);
        }
コード例 #7
0
        // Differentiation methods - extend to include more 2 and 3 point recipes with foward & backward interpolations & variable step.

        public static Differentiation D2PointCenter()
        {
            const double h = 0.000001; // h could vary in an adaptive algorithm

            Differentiation differentiation = (f, x) =>
                                              (f(x + h) - f(x - h)) / (2 * h);

            return(differentiation);
        }
コード例 #8
0
 public Examination()
 {
     SemesterNumber = 0;
     Name           = "Anonymous";
     TeacherName    = "Anonymous";
     Diff           = Differentiation.NonDifferentiated;
     Date           = DateTime.Now;
     Mark           = 0;
 }
コード例 #9
0
        public void Post(int id, [FromBody] string base64Encoded)
        {
            Differentiation diff;
            string          left  = HttpContext.Request.Path.Value.Contains("left") ? base64Encoded : null;
            string          right = HttpContext.Request.Path.Value.Contains("right") ? base64Encoded : null;

            diff = new Differentiation(id, left, right);
            _differentiationService.CreateOrUpdate(diff);
        }
コード例 #10
0
 public Examination(
     int semesterNumber,
     string name,
     string teacherName,
     int mark,
     Differentiation diff,
     string date)
     : this(semesterNumber, name, teacherName, mark, diff,
            DateTime.ParseExact(date, Person.FORMAT, Person.CI))
 {
 }
コード例 #11
0
        public void Different_sizes_must_return_different_size_message()
        {
            //Arrange
            var expectedResult = new List <string> {
                "The files are different sizes."
            };
            var diff = new Differentiation(1, "dGVjZSAyMjIyMjI=", "dGVjZSAy");

            //Act
            var result = diff.Differentiate();

            //Assert
            Assert.Equal(expectedResult, result);
        }
コード例 #12
0
        public void Equal_left_and_right_must_return_equal_message()
        {
            //Arrange
            var expectedResult = new List <string> {
                "The files are equal."
            };
            var diff = new Differentiation(1, "dGVjZSAy", "dGVjZSAy");

            //Act
            var result = diff.Differentiate();

            //Assert
            Assert.Equal(expectedResult, result);
        }
コード例 #13
0
        public void Same_sizes_with_different_content_must_return_differences()
        {
            //Arrange
            var expectedResult = new List <string> {
                "Offset: 2, length: 2"
            };
            var diff = new Differentiation(1, "dGVjZSAy", "dGVzdCAy");

            //Act
            var result = diff.Differentiate();

            //Assert
            Assert.Equal(expectedResult, result);
        }
コード例 #14
0
        public void Get_with_existent_id_must_return_diff()
        {
            //Arrange
            var repository             = A.Fake <IRepository>();
            var differentiationService = new DifferentiationService(repository);
            var diff = new Differentiation(1, "dGVjZSAy", "dGVzdCAy");

            A.CallTo(() => repository.GetById <Differentiation>(1)).Returns(diff);

            //Act
            var result = differentiationService.Get(1);

            //Assert
            Assert.NotNull(result);
        }
コード例 #15
0
 public Examination(
     int semesterNumber,
     string name,
     string teacherName,
     int mark,
     Differentiation diff,
     DateTime date)
 {
     SemesterNumber = semesterNumber;
     Name           = name;
     TeacherName    = teacherName;
     Mark           = mark;
     Diff           = diff;
     Date           = date;
 }
コード例 #16
0
        public void Update_with_valid_differentiation_must_succeed(int id, string left, string right)
        {
            //Arrange
            var repository             = A.Fake <IRepository>();
            var differentiationService = new DifferentiationService(repository);
            var diff = new Differentiation(id, left, right);

            A.CallTo(() => repository.GetById <Differentiation>(id)).Returns(diff);

            //Act
            var result = differentiationService.CreateOrUpdate(diff);

            //Assert
            Assert.NotNull(result);
        }
コード例 #17
0
        /// <summary>
        /// Partial differentiation of z.
        /// </summary>
        /// <param name="fxy">The function f(x,y).</param>
        /// <param name="a">The parameter a.</param>
        /// <param name="b">The parameter b.</param>
        public static double PartialDifferentiationz(Functionxy fxy, double a, double b)
        {
            Differentiation diff = D2PointCenter(); // Could be a parameter.

            return(diff((double z) => fxy(a, z), b));
        }
コード例 #18
0
 /// <summary>
 /// Length of curve f(x) from x=a to x=b.
 /// </summary>
 /// <param name="f">The function f(x).</param>
 /// <param name="a">The starting point a.</param>
 /// <param name="b">The ending point b.</param>
 /// <param name="intMethod">The integration method.</param>
 /// <param name="n">The n.</param>
 /// <param name="diffMethod">The differation method.</param>
 public static double CurveLength(Function f, double a, double b, Integral intMethod, int n, Differentiation diffMethod)
 {
     return(intMethod((double x) => Math.Sqrt(1 + Math.Pow(diffMethod(f, x), 2)), a, b, n));
 }