Exemple #1
0
        /// <summary>
        /// Calculates tangent of the interval of angles.
        /// </summary>
        /// <param name="x">An interval represents the angle in radians.</param>
        public static Interval Tan(Interval x)
        {
            if (Cos(x).Contains(0))
            {
                throw new ArgumentException();
            }

            return new Interval(Math.Tan(x.A), Math.Tan(x.B), x.Epsilon);
        }
Exemple #2
0
        /// <summary>
        /// Calculates a cosine of the interval.
        /// </summary>
        /// <param name="x">A fuzzy number represents the angle in radians.</param>
        public static Interval Cos(Interval x)
        {
            double a, b, extreme;
            extreme = Math.Floor(x.A / Math.PI) * Math.PI;

            if (x.Contains(extreme))
            {
                a = Math.Cos(extreme);
            }
            else
            {
                extreme += Math.PI;

                if (x.Contains(extreme))
                {
                    a = Math.Cos(extreme);
                }
                else
                {
                    a = Math.Cos(x.A);
                    b = Math.Cos(x.B);

                    return b > a
                        ? new Interval(a, b, x.Epsilon)
                        : new Interval(b, a, x.Epsilon);
                }
            }

            extreme += Math.PI;

            if (x.Contains(extreme))
            {
                b = Math.Cos(extreme);
            }
            else if (a > 0)
            {
                b = Math.Min(Math.Cos(x.A), Math.Cos(x.B));
            }
            else
            {
                b = Math.Max(Math.Cos(x.A), Math.Cos(x.B));
            }

            return b > a
                ? new Interval(a, b, x.Epsilon)
                : new Interval(b, a, x.Epsilon);
        }
Exemple #3
0
        /// <summary>
        /// Calculates a value of the interval raised to the specified power.
        /// </summary>
        /// <param name="x">Base</param>
        /// <param name="y">Exponent</param>
        public static Interval Pow(Interval x, double y)
        {
            var a = Math.Pow(x.A, y);
            var b = Math.Pow(x.B, y);
            if (a > b)
            {
                var tmp = a;
                a = b;
                b = tmp;
            }

            if (x.Contains(0) && a > 0)
            {
                a = 0;
            }

            return new Interval(a, b, x.Epsilon);
        }
Exemple #4
0
        private static Interval Atan2(Interval y, Interval x, bool rotated)
        {
            double a1, a2, a3, a4;
            var epsilon = Math.Max(y.Epsilon, x.Epsilon);

            if (rotated)
            {
                if (y.Contains(0) && x.Contains(0))
                {
                    return new Interval(-1.5 * Math.PI, 0.5 * Math.PI, epsilon);
                }

                a1 = Atan2Rotated(y.A, x.A);
                a2 = Atan2Rotated(y.A, x.B);
                a3 = Atan2Rotated(y.B, x.B);
                a4 = Atan2Rotated(y.B, x.A);
            }
            else
            {
                if (y.Contains(0) && x.Contains(0))
                {
                    return new Interval(-Math.PI, Math.PI, epsilon);
                }

                a1 = Math.Atan2(y.A, x.A);
                a2 = Math.Atan2(y.A, x.B);
                a3 = Math.Atan2(y.B, x.B);
                a4 = Math.Atan2(y.B, x.A);
            }

            return new Interval(
                    Math.Min(Math.Min(a1, a2), Math.Min(a3, a4)),
                    Math.Max(Math.Max(a1, a2), Math.Max(a3, a4)),
                    epsilon
                );
        }
Exemple #5
0
 /// <summary>
 /// Calculates a sine of the interval of angles.
 /// </summary>
 /// <param name="x">A interval represents the angle in radians.</param>
 public static Interval Sin(Interval x)
 {
     return Cos(x - Math.PI / 2);
 }
Exemple #6
0
 /// <summary>
 /// Returns the smaller of two intervals.
 /// </summary>
 public static Interval Min(Interval x, Interval y)
 {
     return new Interval(Math.Min(x.A, y.A), Math.Min(x.B, y.B), Math.Max(x.Epsilon, y.Epsilon));
 }
Exemple #7
0
 /// <summary>
 /// Calculates e raised to the specified interval.
 /// </summary>
 /// <param name="X">Exponent</param>
 public static Interval Exp(Interval x)
 {
     return new Interval(Math.Exp(x.A), Math.Exp(x.B), x.Epsilon);
 }