Пример #1
0
        /// <summary>
        /// Computes the quotient of two multi-intervals
        /// </summary>.
        public static MultiInterval Divide(MultiInterval dividend, MultiInterval divisor)
        {
            List <Interval> aIntervals = dividend._intervals;
            List <Interval> bIntervals = divisor._intervals;

            MultiInterval multiInterval = new MultiInterval();

            for (int i = 0; i < aIntervals.Count; i++)
            {
                for (int j = 0; j < bIntervals.Count; j++)
                {
                    Interval intervalDivisor = bIntervals[j];

                    if (intervalDivisor.Contains(0))
                    {
                        multiInterval.Add(Interval.Divide(aIntervals[i], new Interval(0, intervalDivisor.UpperBound)));
                        multiInterval.Add(Interval.Divide(aIntervals[i], new Interval(intervalDivisor.LowerBound, 0)));
                    }
                    else
                    {
                        multiInterval.Add(Interval.Divide(aIntervals[i], intervalDivisor));
                    }
                }
            }

            return(multiInterval);
        }
Пример #2
0
        /// <summary>
        /// Computes the union of two multi-intervals
        /// </summary>
        public static MultiInterval Union(MultiInterval a, MultiInterval b)
        {
            MultiInterval multiInterval = a.Clone();

            foreach (var interval in b._intervals)
            {
                multiInterval.Add(interval);
            }

            return(multiInterval);
        }
Пример #3
0
        /// <summary>
        /// Extends the multi-interval to contain the specified value.
        /// </summary>
        public MultiInterval Extend(double value)
        {
            MultiInterval multiInterval = new MultiInterval();

            for (int i = 0; i < _intervals.Count; i++)
            {
                Interval extended = _intervals[i].Extend(value);
                multiInterval.Add(extended);
            }

            return(multiInterval);
        }
Пример #4
0
        /// <summary>
        /// Computes the product of two multi-intervals
        /// </summary>
        public static MultiInterval Multiply(MultiInterval a, MultiInterval b)
        {
            List <Interval> aIntervals = a._intervals;
            List <Interval> bIntervals = b._intervals;

            MultiInterval multiInterval = new MultiInterval();

            for (int i = 0; i < aIntervals.Count; i++)
            {
                for (int j = 0; j < bIntervals.Count; j++)
                {
                    Interval product = Interval.Multiply(aIntervals[i], bIntervals[j]);
                    multiInterval.Add(product);
                }
            }

            return(multiInterval);
        }
Пример #5
0
        /// <summary>
        /// Subtracts two multi-intervals
        /// </summary>
        public static MultiInterval Subtract(MultiInterval a, MultiInterval b)
        {
            List <Interval> aIntervals = a._intervals;
            List <Interval> bIntervals = b._intervals;

            MultiInterval multiInterval = new MultiInterval();

            for (int i = 0; i < aIntervals.Count; i++)
            {
                for (int j = 0; j < bIntervals.Count; j++)
                {
                    Interval difference = Interval.Subtract(aIntervals[i], bIntervals[j]);
                    multiInterval.Add(difference);
                }
            }

            return(multiInterval);
        }
Пример #6
0
        /// <summary>
        /// Computes and returns the intersection between <paramref name="a"/> and <paramref name="b"/>
        /// </summary>
        public static MultiInterval Intersection(MultiInterval a, MultiInterval b)
        {
            List <Interval> aIntervals = a._intervals;
            List <Interval> bIntervals = b._intervals;

            MultiInterval multiInterval = new MultiInterval();

            for (int i = 0; i < aIntervals.Count; i++)
            {
                for (int j = 0; j < bIntervals.Count; j++)
                {
                    Interval intersection = Interval.Intersection(aIntervals[i], bIntervals[j]);
                    if (!intersection.IsEmpty)
                    {
                        multiInterval.Add(intersection);
                    }
                }
            }

            return(multiInterval);
        }