Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/28/19 14:34:17 (5 years ago)
Author:
gkronber
Message:

#2966: fixed calculation for intervals of Sqr, Sqrt, Cube, CubeRoot

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval.cs

    r16571 r16631  
    201201
    202202    public static Interval Square(Interval a) {
    203       return Power(a, new Interval(2, 2));
    204     }
    205 
    206     public static Interval Cubic(Interval a) {
    207       return Power(a, new Interval(3, 3));
     203      if (a.UpperBound <= 0) return new Interval(a.UpperBound * a.UpperBound, a.LowerBound * a.LowerBound);     // interval is negative
     204      else if (a.LowerBound >= 0) return new Interval(a.LowerBound * a.LowerBound, a.UpperBound * a.UpperBound); // interval is positive
     205      else return new Interval(0, Math.Max(a.LowerBound*a.LowerBound, a.UpperBound*a.UpperBound)); // interval goes over zero
     206    }
     207
     208    public static Interval Cube(Interval a) {
     209      return new Interval(Math.Pow(a.LowerBound, 3), Math.Pow(a.UpperBound, 3));
    208210    }
    209211
     
    216218
    217219    public static Interval SquareRoot(Interval a) {
    218       return Root(a, new Interval(2, 2));
     220      if (a.LowerBound < 0) return new Interval(double.NaN, double.NaN);
     221      return new Interval(Math.Sqrt(a.LowerBound), Math.Sqrt(a.UpperBound));
    219222    }
    220223
    221224    public static Interval CubicRoot(Interval a) {
    222       return Root(a, new Interval(3, 3));
     225      if (a.LowerBound < 0) return new Interval(double.NaN, double.NaN);
     226      return new Interval(Math.Pow(a.LowerBound, 1.0/3), Math.Pow(a.UpperBound, 1.0/3));
    223227    }
    224228    #endregion
Note: See TracChangeset for help on using the changeset viewer.