/* CALCULATION -- MULTIPLICATION */ private static IntervalStruct IntervalMultiplication(IntervalStruct x, IntervalStruct y) { // Comparing a1 * a2 and a1 * b2 double min = System.Math.Min(x.GetMinBound() * y.GetMinBound(), x.GetMinBound() * y.GetMaxBound()); double max = System.Math.Max(x.GetMinBound() * y.GetMinBound(), x.GetMinBound() * y.GetMaxBound()); // Comparing the previous results to b1 * a2 min = System.Math.Min(min, x.GetMaxBound() * y.GetMinBound()); max = System.Math.Max(max, x.GetMaxBound() * y.GetMinBound()); // Comparing the previous results to b1 * b2 min = System.Math.Min(min, x.GetMaxBound() * y.GetMaxBound()); max = System.Math.Max(max, x.GetMaxBound() * y.GetMaxBound()); return(new IntervalStruct("", min, max, true, true)); }
/* CALCULATION -- EXPONENTS */ private static IntervalStruct IntervalExponents(IntervalStruct x, IntervalStruct y) { IntervalStruct exp = null; if (x.GetMinBound() == x.GetMaxBound()) { exp = IntervalAsExponent(x.GetMinBound(), y); } else if (y.GetMinBound() == y.GetMaxBound()) { exp = IntervalAsBase(x, y.GetMinBound()); } else { frm_Main.UpdateLog("Error: An unsupported operation was encountered while solving for the range of the equation (Exponents)." + System.Environment.NewLine); } return(exp); }
private static IntervalStruct IntervalDivisionNegativeDivisor(IntervalStruct x, IntervalStruct y) { double min = 0; double max = 0; // 0 < a1 <= b1 if (x.GetMinBound() > 0) { min = x.GetMaxBound() / y.GetMaxBound(); max = x.GetMinBound() / y.GetMinBound(); } // a1 = 0, a1 <= b1 else if (x.GetMinBound() == 0) { min = x.GetMaxBound() / y.GetMaxBound(); max = 0; } // a1 < 0 < b1 else if (x.GetMaxBound() > 0) { min = x.GetMaxBound() / y.GetMaxBound(); max = x.GetMinBound() / y.GetMaxBound(); } // b1 = 0, a1 <= b1 else if (x.GetMaxBound() == 0) { min = 0; max = x.GetMinBound() / y.GetMaxBound(); } //a1 <= b1 < 0 else if (x.GetMaxBound() < 0) { min = x.GetMaxBound() / y.GetMinBound(); max = x.GetMinBound() / y.GetMaxBound(); } return(new IntervalStruct("", min, max, true, true)); }
private static IntervalStruct IntervalAsBase(IntervalStruct x, double n) { IntervalStruct exp = null; double roundedN = System.Math.Round(n); if (n >= 0) { if (n != roundedN) { frm_Main.UpdateLog("Warning: The value provided for the exponent" + System.Convert.ToString(n) + "is not a natural number. It has been rounded to " + System.Convert.ToString(roundedN) + System.Environment.NewLine); } if (roundedN % 2 != 0) { exp = new IntervalStruct("", System.Math.Pow(x.GetMinBound(), roundedN), System.Math.Pow(x.GetMaxBound(), roundedN), true, true); } else if (x.GetMinBound() >= 0) { exp = new IntervalStruct("", System.Math.Pow(x.GetMinBound(), roundedN), System.Math.Pow(x.GetMaxBound(), roundedN), true, true); } else if (x.GetMaxBound() < 0) { exp = new IntervalStruct("", System.Math.Pow(x.GetMaxBound(), roundedN), System.Math.Pow(x.GetMinBound(), roundedN), true, true); } else { exp = new IntervalStruct("", 0, System.Math.Max(System.Math.Pow(x.GetMinBound(), roundedN), System.Math.Pow(x.GetMaxBound(), roundedN)), true, true); } } else { frm_Main.UpdateLog("Error: An unsupported operation was encountered while solving for the range of the equation (Exponent < 0)." + System.Environment.NewLine); } return(exp); }
private static IntervalStruct IntervalAsExponent(double b, IntervalStruct x) { IntervalStruct exp = null; if (b > 1) { exp = new IntervalStruct("", System.Math.Pow(b, x.GetMinBound()), System.Math.Pow(b, x.GetMaxBound()), true, true); } else { frm_Main.UpdateLog("Error: An unsupported operation was encountered while solving for the range of the equation (Exponent base <= 1)." + System.Environment.NewLine); } return(exp); }
/* CALCULATION -- DIVISION */ private static IntervalStruct IntervalDivision(IntervalStruct x, IntervalStruct y) { IntervalStruct divInterval = null; // 0 < a2 <= b2 if (y.GetMinBound() > 0) { divInterval = IntervalDivisionPositiveDivisor(x, y); } // a2 <= b2 < 0 else if (y.GetMaxBound() < 0) { divInterval = IntervalDivisionNegativeDivisor(x, y); } // a2 = 0 v b2 = 0 else { frm_Main.UpdateLog("Error: An unsupported operation was encountered while solving for the range of the equation (Mixed interval division)." + System.Environment.NewLine); } return(divInterval); }
/* CALCULATION -- SUBTRACTION */ private static IntervalStruct IntervalSubtraction(IntervalStruct x, IntervalStruct y) { return(new IntervalStruct("", x.GetMinBound() - y.GetMinBound(), x.GetMaxBound() - y.GetMaxBound(), true, true)); }