/// <summary> /// Reverses the value of its argument. /// </summary> /// <param name="args">The args contains one item : logical. /// Logical is a value or expression that can be evaluated to <see langword="true" /> /// or <see langword="false" />.</param> /// <returns> /// A <see cref="T:System.Boolean" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); CalcReference objA = args[0] as CalcReference; CalcArray array = args[0] as CalcArray; if (!object.ReferenceEquals(objA, null)) { if (objA.RangeCount > 1) { return(CalcErrors.Value); } return(new UnaryCompositeConcreteReference(objA.GetSource(), objA.GetRow(0), objA.GetColumn(0), objA.GetRowCount(0), objA.GetColumnCount(0), new Func <object, object>(this.EvaluateSingleValue))); } if (object.ReferenceEquals(array, null)) { return(this.EvaluateSingleValue(args[0])); } object[,] values = new object[array.RowCount, array.ColumnCount]; for (int i = 0; i < array.RowCount; i++) { for (int j = 0; j < array.ColumnCount; j++) { values[i, j] = this.EvaluateSingleValue(array.GetValue(i, j)); } } return(new ConcreteArray <object>(values)); }
/// <summary> /// Counts the cells that contain numbers in a field (column) of /// records in a list or database that match conditions that you specify. /// </summary> /// <param name="args"><para> /// The args contains 3 items: database, field, criteria. /// </para> /// <para> /// Database is the range of cells that makes up the list or database. /// A database is a list of related data in which rows of related /// information are records, and columns of data are fields. /// The first row of the list contains labels for each column. /// </para> /// <para> /// Field indicates which column is used in the function. /// Enter the column label enclosed between double quotation marks, /// such as "Age" or "Yield," or a number (without quotation marks) /// that represents the position of the column within the list: /// 1 for the first column, 2 for the second column, and so on. /// </para> /// <para> /// Criteria is the range of cells that contains the conditions you /// specify. You can use any range for the criteria argument, /// as long as it includes at least one column label and at least /// one cell below the column label in which you specify a condition for the column. /// </para></param> /// <returns> /// A <see cref="T:System.Object" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); if (((args[0] == null) || (args[1] == null)) || (args[2] == null)) { throw new ArgumentNullException(); } CalcArray database = CalcConvert.ToArray(args[0]); object field = args[1]; CalcArray criteria = CalcConvert.ToArray(args[2]); double num = 0.0; if (CalcHelper.ArgumentExists(args, 1)) { IEnumerator enumerator = new DatabaseEnumerator(database, field, criteria); while (enumerator.MoveNext()) { if (enumerator.Current != null) { num++; } } } else { IEnumerator enumerator2 = new DatabaseEnumerator(database, criteria); while (enumerator2.MoveNext()) { num++; } } return(CalcConvert.ToResult(num)); }
/// <summary> /// Returns one value if a condition you specify evaluates to <see langword="true" /> /// and another value if it evaluates to <see langword="false" />. /// </summary> /// <param name="args"> /// <para> /// The args contains three items: logical_test, value_if_true and value_if_false. /// </para> /// <para> /// logical_test is any value or expression that can be evaluated to <see langword="true" /> or <see langword="false" />. /// For example, A10=100 is a logical expression; if the value in cell A10 is equal to 100, /// the expression evaluates to <see langword="true" />. Otherwise, the expression evaluates to <see langword="false" />. /// This argument can use any comparison calculation operator. /// </para> /// <para> /// value_if_true is the value that is returned if logical_test is <see langword="true" />. For example, /// if this argument is the text string "Within budget" and the logical_test argument evaluates to <see langword="true" />, /// then the IF function displays the text "Within budget". If logical_test is <see langword="true" /> and value_if_true is blank, /// this argument returns 0 (zero). To display the word <see langword="true" />, use the logical value <see langword="true" /> for this argument. /// Value_if_true can be another formula. /// </para> /// <para> /// value_if_false is the value that is returned if logical_test is <see langword="false" />. For example, /// if this argument is the text string "Over budget" and the logical_test argument evaluates to <see langword="false" />, /// then the IF function displays the text "Over budget". If logical_test is <see langword="false" /> and value_if_false is omitted, /// (that is, after value_if_true, there is no comma), then the logical value <see langword="false" /> is returned. /// If logical_test is <see langword="false" /> and value_if_false is blank (that is, after value_if_true, /// there is a comma followed by the closing parenthesis), /// then the value 0 (zero) is returned. Value_if_false can be another formula. /// </para></param> /// <returns> /// A <see cref="T:System.Object" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); object param = args[0]; object obj3 = args[1]; object obj4 = CalcHelper.ArgumentExists(args, 2) ? args[2] : ((bool)false); if (CalcHelper.TryExtractToSingleValue(param, out param)) { return(EvaluateSingleValue(param, obj3, obj4)); } bool flag = CalcHelper.TryExtractToSingleValue(obj3, out obj3); bool flag2 = CalcHelper.TryExtractToSingleValue(obj4, out obj4); CalcArray array = param as CalcArray; object[,] values = new object[array.RowCount, array.ColumnCount]; for (int i = 0; i < array.RowCount; i++) { for (int j = 0; j < array.ColumnCount; j++) { values[i, j] = EvaluateSingleValue(array.GetValue(i, j), flag ? obj3 : CalcHelper.GetArrayValue(obj3 as CalcArray, i, j), flag2 ? obj4 : CalcHelper.GetArrayValue(obj4 as CalcArray, i, j)); } } return(new ConcreteArray <object>(values)); }
/// <summary> /// Multiplies the values in a field (column) of records in a list /// or database that match conditions that you specify. /// </summary> /// <param name="args"><para> /// The args contains 3 items: database, field, criteria. /// </para> /// <para> /// Database is the range of cells that makes up the list or database. /// A database is a list of related data in which rows of related /// information are records, and columns of data are fields. /// The first row of the list contains labels for each column. /// </para> /// <para> /// Field indicates which column is used in the function. /// Enter the column label enclosed between double quotation marks, /// such as "Age" or "Yield," or a number (without quotation marks) /// that represents the position of the column within the list: /// 1 for the first column, 2 for the second column, and so on. /// </para> /// <para> /// Criteria is the range of cells that contains the conditions you /// specify. You can use any range for the criteria argument, /// as long as it includes at least one column label and at least /// one cell below the column label in which you specify a condition for the column. /// </para></param> /// <returns> /// A <see cref="T:System.Object" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); if (((args[0] == null) || (args[1] == null)) || (args[2] == null)) { throw new ArgumentNullException(); } CalcArray database = CalcConvert.ToArray(args[0]); object field = args[1]; CalcArray criteria = CalcConvert.ToArray(args[2]); double num = 1.0; IEnumerator enumerator = new DatabaseEnumerator(database, field, criteria); while (enumerator.MoveNext()) { object current = enumerator.Current; if (CalcConvert.IsNumber(current)) { double num2; if (!CalcConvert.TryToDouble(current, out num2, true)) { return(CalcErrors.Value); } num *= num2; } else if (current is CalcError) { return(current); } } return(CalcConvert.ToResult(num)); }
public DatabaseEnumerator(CalcArray database, CalcArray criteria) { this.database = database; this.criteria = criteria; this.row = 0; this.column = -1; if ((database.RowCount < 2) || (database.ColumnCount < 1)) { throw new InvalidCastException(); } if ((criteria.RowCount < 2) || (criteria.ColumnCount < 1)) { throw new InvalidCastException(); } }
private int ColumnIndex(CalcArray database, object field) { if (!(field is string)) { return(CalcConvert.ToInt(field) - 1); } for (int i = 0; i < database.ColumnCount; i++) { string str = CalcConvert.ToString(database.GetValue(0, i)); if ((str != null) && str.Equals((string)(field as string), StringComparison.OrdinalIgnoreCase)) { return(i); } } return(-1); }
public DatabaseEnumerator(CalcArray database, object field, CalcArray criteria) { this.database = database; this.criteria = criteria; this.row = 0; this.column = this.ColumnIndex(database, field); if ((database.RowCount < 2) || (database.ColumnCount < 1)) { throw new InvalidCastException(); } if ((criteria.RowCount < 2) || (criteria.ColumnCount < 1)) { throw new InvalidCastException(); } if ((this.column < 0) || (database.ColumnCount <= this.column)) { throw new InvalidCastException(); } }
/// <summary> /// Adds the cells specified by a given criteria. /// </summary> /// <param name="args"><para> /// The args contains 2 - 3 items: range, criteria, [sum_range]. /// </para> /// <para> /// Range is the range of cells that you want evaluated by criteria. /// </para> /// <para> /// Criteria is the criteria in the form of a number, expression, /// or text that defines which cells will be added. /// </para> /// <para> /// [Sum_range] are the actual cells to add if their corresponding /// cells in range match criteria. /// </para></param> /// <returns> /// A <see cref="T:System.Double" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); object range = args[0]; object criteria = args[1]; if (criteria == null) { throw new ArgumentException("criteria"); } object sumRange = CalcHelper.ArgumentExists(args, 2) ? args[2] : args[0]; CalcReference objA = args[1] as CalcReference; if (!object.ReferenceEquals(objA, null)) { int num = objA.GetRowCount(0); int num2 = objA.GetColumnCount(0); if ((num == 1) && (num2 == 1)) { return(EvaluateSingleCriteria(objA.GetValue(0, 0, 0), range, sumRange)); } return(new TernaryCompositeConcreteReference(objA.GetSource(), objA.GetRow(0), objA.GetColumn(0), num, num2, new Func <object, object, object, object>(CalcSumIfFunction.EvaluateSingleCriteria), range, sumRange)); } CalcArray array = args[1] as CalcArray; if (object.ReferenceEquals(array, null)) { return(EvaluateSingleCriteria(criteria, range, sumRange)); } int rowCount = array.RowCount; int columnCount = array.ColumnCount; object[,] values = new object[rowCount, columnCount]; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { values[i, j] = EvaluateSingleCriteria(array.GetValue(i, j), range, sumRange); } } return(new ConcreteArray <object>(values)); }
/// <summary> /// Returns the average (arithmetic mean) of all the cells in a range /// that meet a given criteria. /// </summary> /// <param name="args"><para> /// The args contains 2 - 3 items: range, criteria, [average_range]. /// </para> /// <para> /// Range is one or more cells to average, including numbers or names, /// arrays, or references that contain numbers. /// </para> /// <para> /// Criteria is the criteria in the form of a number, expression, cell /// reference, or text that defines which cells are averaged. /// </para> /// <para> /// [Average_range] is the actual set of cells to average. If omitted, /// range is used. /// </para></param> /// <returns> /// A <see cref="T:System.Object" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); object range = args[0]; object criteria = args[1]; object sumRange = CalcHelper.ArgumentExists(args, 2) ? args[2] : args[0]; CalcReference objA = args[1] as CalcReference; if (!object.ReferenceEquals(objA, null)) { int num = objA.GetRowCount(0); int num2 = objA.GetColumnCount(0); object[,] objArray = new object[num, num2]; for (int j = 0; j < num; j++) { for (int k = 0; k < num2; k++) { objArray[j, k] = this.EvaluateSingleCriteria(range, objA.GetValue(0, j, k), sumRange); } } return(new ConcreteArray <object>(objArray)); } CalcArray array = args[1] as CalcArray; if (object.ReferenceEquals(array, null)) { return(this.EvaluateSingleCriteria(range, criteria, sumRange)); } int rowCount = array.RowCount; int columnCount = array.ColumnCount; object[,] values = new object[rowCount, columnCount]; for (int i = 0; i < rowCount; i++) { for (int m = 0; m < columnCount; m++) { values[i, m] = this.EvaluateSingleCriteria(range, array.GetValue(i, m), sumRange); } } return(new ConcreteArray <object>(values)); }
/// <summary> /// Estimates the standard deviation of a population based on a /// sample by using the numbers in a field (column) of records /// in a list or database that match conditions that you specify. /// </summary> /// <param name="args"><para> /// The args contains 3 items: database, field, criteria. /// </para> /// <para> /// Database is the range of cells that makes up the list or database. /// A database is a list of related data in which rows of related /// information are records, and columns of data are fields. /// The first row of the list contains labels for each column. /// </para> /// <para> /// Field indicates which column is used in the function. /// Enter the column label enclosed between double quotation marks, /// such as "Age" or "Yield," or a number (without quotation marks) /// that represents the position of the column within the list: /// 1 for the first column, 2 for the second column, and so on. /// </para> /// <para> /// Criteria is the range of cells that contains the conditions you /// specify. You can use any range for the criteria argument, /// as long as it includes at least one column label and at least /// one cell below the column label in which you specify a condition for the column. /// </para></param> /// <returns> /// A <see cref="T:System.Object" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); if (((args[0] == null) || (args[1] == null)) || (args[2] == null)) { throw new ArgumentNullException(); } CalcArray database = CalcConvert.ToArray(args[0]); object field = args[1]; CalcArray criteria = CalcConvert.ToArray(args[2]); double num = 0.0; double num2 = 0.0; double num3 = 0.0; IEnumerator enumerator = new DatabaseEnumerator(database, field, criteria); while (enumerator.MoveNext()) { object current = enumerator.Current; if (CalcConvert.IsNumber(current)) { double num4; if (!CalcConvert.TryToDouble(current, out num4, true)) { return(CalcErrors.Value); } num += num4; num2 += num4 * num4; num3++; } else if (CalcConvert.IsError(current)) { return(current); } } if (num3 <= 1.0) { return(CalcErrors.DivideByZero); } return(CalcConvert.ToResult(Math.Sqrt(Math.Max((double)0.0, (double)(((num3 * num2) - (num * num)) / (num3 * (num3 - 1.0))))))); }
/// <summary> /// /// </summary> /// <param name="criteria"></param> /// <returns></returns> /// <remarks> /// In Excel, a string criteria with out a leading operator is treated as a /// string begins with operation. In OpenOffice, a string criteria with out /// a leading operator is treated as a string equals operation. We are /// supporting the OpenOffice behavior. /// /// In Excel and OpenOffice, a string equals criteria supports regular /// expressions. We are not supporting regular expressions. /// </remarks> private CriteriaEvaluator CreateEvaluator(object criteria) { if (criteria is string) { string s = (string)((string)criteria); double result = 0.0; for (int i = 0; i < operators.Length; i++) { if (s.StartsWith(operators[i].Name)) { s = s.Substring(operators[i].Name.Length); if (double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out result)) { criteria = (double)result; } else if ("true".Equals(s, StringComparison.OrdinalIgnoreCase)) { criteria = true; } else if ("false".Equals(s, StringComparison.OrdinalIgnoreCase)) { criteria = false; } else { criteria = s; } return(new CriteriaEvaluator(operators[i], criteria)); } } return(new CriteriaEvaluator(CalcBinaryOperators.Equal, criteria)); } if (criteria != null) { return(new CriteriaEvaluator(CalcBinaryOperators.Equal, criteria)); } return(null); }
/// <summary> /// Returns the <see cref="T:System.String" /> product of 1 to 255 complex numbers in x + yi or x + yj text format. /// </summary> /// <param name="args"><para> /// The args contains 1 - 255 items: inumber1, [inumber2], [inumber3], .. /// </para> /// <para> /// Inumber1, inumber2,¡ are 1 to 255 complex numbers to multiply. /// </para></param> /// <returns> /// A <see cref="T:System.String" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); double real = 1.0; double imag = 0.0; for (int i = 0; i < args.Length; i++) { if (args[i] is CalcArray) { CalcArray array = (CalcArray)args[i]; for (int j = 0; j < array.RowCount; j++) { for (int k = 0; k < array.ColumnCount; k++) { Complex complex = ComplexConvert.ToComplex(array.GetValue(j, k)); double num6 = real; double num7 = imag; double num8 = complex.Real; double num9 = complex.Imag; real = (num6 * num8) - (num7 * num9); imag = (num6 * num9) + (num7 * num8); } } } else { Complex complex2 = ComplexConvert.ToComplex(args[i]); double num10 = real; double num11 = imag; double num12 = complex2.Real; double num13 = complex2.Imag; real = (num10 * num12) - (num11 * num13); imag = (num10 * num13) + (num11 * num12); } } return(ComplexConvert.ToResult(new Complex(real, imag))); }
internal object EvaluteInternal(object operand, CalcEvaluatorContext context) { CalcArray array = operand as CalcArray; CalcReference reference = operand as CalcReference; if (reference != null) { array = CalcConvert.ToArray(reference); } if (array == null) { return(this.EvaluteSingleValue(operand, context)); } if (array.Length < 1) { return(CalcErrors.Number); } object[,] values = new object[array.RowCount, array.ColumnCount]; CalcOperator.OperatorArray array2 = new CalcOperator.OperatorArray(values); object obj2 = array.GetValue(0); Type type = (obj2 != null) ? obj2.GetType() : typeof(object); for (int i = 0; i < array.RowCount; i++) { for (int j = 0; j < array.ColumnCount; j++) { object obj3 = array.GetValue(i, j); if ((obj3 != null) && (obj3.GetType() != type)) { return(CalcErrors.Number); } object obj4 = this.EvaluteSingleValue(obj3, context); values[i, j] = obj4; } } return(array2); }
/// <summary> /// Extracts a single value from a column of a list or database /// that matches conditions that you specify. /// </summary> /// <param name="args"><para> /// The args contains 3 items: database, field, criteria. /// </para> /// <para> /// Database is the range of cells that makes up the list or database. /// A database is a list of related data in which rows of related /// information are records, and columns of data are fields. /// The first row of the list contains labels for each column. /// </para> /// <para> /// Field indicates which column is used in the function. /// Enter the column label enclosed between double quotation marks, /// such as "Age" or "Yield," or a number (without quotation marks) /// that represents the position of the column within the list: /// 1 for the first column, 2 for the second column, and so on. /// </para> /// <para> /// Criteria is the range of cells that contains the conditions you /// specify. You can use any range for the criteria argument, /// as long as it includes at least one column label and at least /// one cell below the column label in which you specify a condition for the column. /// </para></param> /// <returns> /// A <see cref="T:System.Object" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); if (((args[0] == null) || (args[1] == null)) || (args[2] == null)) { throw new ArgumentNullException(); } CalcArray database = CalcConvert.ToArray(args[0]); object field = args[1]; CalcArray criteria = CalcConvert.ToArray(args[2]); object current = null; IEnumerator enumerator = new DatabaseEnumerator(database, field, criteria); if (enumerator.MoveNext()) { current = enumerator.Current; if (enumerator.MoveNext()) { return(CalcErrors.Number); } return(current); } return(CalcErrors.Value); }
/// <summary> /// Calculates how often values occur within a range of values, and /// then returns a vertical array of numbers. /// </summary> /// <param name="args"><para> /// The args contains 2 items: data_array, bins_array. /// </para> /// <para> /// Data_array is an array of or reference to a set of values for /// which you want to count frequencies. /// </para> /// <para> /// array is an array of or reference to intervals into which you /// want to group the values in data_array. /// </para></param> /// <returns> /// A <see cref="T:System.Object" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); CalcArray array = CalcConvert.ToArray(args[0]); CalcArray array2 = CalcConvert.ToArray(args[1]); int index = 0; for (int i = 0; i < array2.RowCount; i++) { for (int n = 0; n < array2.ColumnCount; n++) { object obj2 = array2.GetValue(i, n); if (CalcConvert.IsError(obj2)) { return(obj2); } if (CalcConvert.IsNumber(obj2)) { index++; } } } for (int j = 0; j < array.RowCount; j++) { for (int num5 = 0; num5 < array.ColumnCount; num5++) { object obj3 = array.GetValue(j, num5); if (CalcConvert.IsError(obj3)) { return(obj3); } } } double[] numArray = new double[index]; double[] values = new double[index + 1]; index = 0; for (int k = 0; k < array2.RowCount; k++) { for (int num7 = 0; num7 < array2.ColumnCount; num7++) { object obj4 = array2.GetValue(k, num7); if (CalcConvert.IsNumber(obj4)) { numArray[index++] = CalcConvert.ToDouble(obj4); } } } Array.Sort <double>(numArray); for (int m = 0; m < array.RowCount; m++) { for (int num9 = 0; num9 < array.ColumnCount; num9++) { object obj5 = array.GetValue(m, num9); if (CalcConvert.IsNumber(obj5)) { double num10 = CalcConvert.ToDouble(obj5); bool flag = false; for (int num11 = 0; !flag && (num11 < index); num11++) { if (num10 <= numArray[num11]) { values[num11]++; flag = true; } } if (!flag) { values[index]++; } } } } return(new ConcreteArray(values)); }
/// <summary> /// Returns the <see cref="T:Dt.CalcEngine.CalcArray" /> coordinates for a straight line that best fits your data. /// </summary> /// <param name="args"><para> /// The args contains 1 - 4 items: known_y's, [known_x's], [const], [stats]. /// </para> /// <para> /// Known_y's is the set of y-values you already know in the relationship y = mx + b. /// </para> /// <para> /// Known_x's is an optional set of x-values that you may already know in the relationship y = mx + b. /// </para> /// <para> /// Const is a logical value specifying whether to force the constant b to equal 0. /// </para> /// <para> /// Stats is a logical value specifying whether to return additional regression statistics. /// </para></param> /// <returns> /// A <see cref="T:Dt.CalcEngine.CalcArray" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { int rowCount; int columnCount; double[] numArray; double[,] numArray2; base.CheckArgumentsLength(args); CalcArray array = CalcConvert.ToArray(args[0]); CalcArray array2 = CalcHelper.ArgumentExists(args, 1) ? CalcConvert.ToArray(args[1]) : new DefaultKnownX(array.RowCount, array.ColumnCount); bool flag = CalcHelper.ArgumentExists(args, 2) ? CalcConvert.ToBool(args[2]) : true; bool flag2 = CalcHelper.ArgumentExists(args, 3) ? CalcConvert.ToBool(args[3]) : false; for (int i = 0; i < array.RowCount; i++) { for (int n = 0; n < array.ColumnCount; n++) { if (array.GetValue(i, n) is CalcError) { return(array.GetValue(i, n)); } if (!CalcConvert.IsNumber(array.GetValue(i, n))) { return(CalcErrors.Value); } } } for (int j = 0; j < array2.RowCount; j++) { for (int num4 = 0; num4 < array2.ColumnCount; num4++) { if (array2.GetValue(j, num4) is CalcError) { return(array2.GetValue(j, num4)); } if (!CalcConvert.IsNumber(array2.GetValue(j, num4))) { return(CalcErrors.Value); } } } if (((array.RowCount == array2.RowCount) && (array.ColumnCount == array2.ColumnCount)) && (flag || !flag2)) { double num11; double num12; double num5 = array2.RowCount * array2.ColumnCount; double num6 = 0.0; double num7 = 0.0; double num8 = 0.0; double num9 = 0.0; double num10 = 0.0; for (int num13 = 0; num13 < array2.RowCount; num13++) { for (int num14 = 0; num14 < array2.ColumnCount; num14++) { double num15; double num16; if (!CalcConvert.TryToDouble(array2.GetValue(num13, num14), out num15, true) || !CalcConvert.TryToDouble(array.GetValue(num13, num14), out num16, true)) { return(CalcErrors.Value); } num6 += num15; num7 += num15 * num15; num8 += num16; num9 += num16 * num16; num10 += num15 * num16; } } if (flag) { num11 = ((num5 * num10) - (num6 * num8)) / ((num5 * num7) - (num6 * num6)); num12 = ((num8 * num7) - (num6 * num10)) / ((num5 * num7) - (num6 * num6)); } else { num11 = num10 / num7; num12 = 0.0; } object[,] objArray = new object[flag2 ? 5 : 1, 2]; objArray[0, 0] = (double)num11; objArray[0, 1] = (double)num12; if (flag2) { double num17 = (num5 * num7) - (num6 * num6); double num18 = (num5 * num9) - (num8 * num8); double num19 = (num5 * num10) - (num6 * num8); double num20 = (num9 - (num12 * num8)) - (num11 * num10); double num21 = (num19 * num19) / (num17 * num18); if (num5 < 3.0) { objArray[1, 0] = CalcErrors.Number; objArray[1, 1] = CalcErrors.Number; objArray[2, 1] = CalcErrors.Number; objArray[3, 0] = CalcErrors.Number; } else { objArray[1, 0] = (double)Math.Sqrt((num20 * num5) / (num17 * (num5 - 2.0))); objArray[1, 1] = (double)Math.Sqrt((num20 * num7) / (num17 * (num5 - 2.0))); objArray[2, 1] = (double)Math.Sqrt((num18 - ((num19 * num19) / num17)) / (num5 * (num5 - 2.0))); if (num21 == 1.0) { objArray[3, 0] = CalcErrors.Number; } else { objArray[3, 0] = (num21 * (num5 - 2.0)) / (1.0 - num21); } } objArray[2, 0] = (double)num21; objArray[3, 1] = num5 - 2.0; objArray[4, 0] = (num18 / num5) - num20; objArray[4, 1] = (double)num20; } return(new ConcreteArray(objArray)); } if (((array.ColumnCount != 1) || (array.RowCount != array2.RowCount)) && ((array.RowCount != 1) || (array.ColumnCount != array2.ColumnCount))) { return(CalcErrors.Number); } if (array.ColumnCount == 1) { rowCount = array2.RowCount; columnCount = array2.ColumnCount; numArray2 = new double[rowCount, columnCount]; numArray = new double[rowCount]; for (int num24 = 0; num24 < rowCount; num24++) { double num25; if (!CalcConvert.TryToDouble(array.GetValue(num24, 0), out num25, true)) { return(CalcErrors.Value); } numArray[num24] = num25; } for (int num26 = 0; num26 < rowCount; num26++) { for (int num27 = 0; num27 < columnCount; num27++) { double num28; if (!CalcConvert.TryToDouble(array2.GetValue(num26, num27), out num28, true)) { return(CalcErrors.Value); } numArray2[num26, num27] = num28; } } } else { rowCount = array2.ColumnCount; columnCount = array2.RowCount; numArray2 = new double[rowCount, columnCount]; numArray = new double[rowCount]; for (int num29 = 0; num29 < rowCount; num29++) { double num30; if (!CalcConvert.TryToDouble(array.GetValue(0, num29), out num30, true)) { return(CalcErrors.Value); } numArray[num29] = num30; } for (int num31 = 0; num31 < rowCount; num31++) { for (int num32 = 0; num32 < columnCount; num32++) { double num33; if (!CalcConvert.TryToDouble(array2.GetValue(num32, num31), out num33, true)) { return(CalcErrors.Value); } numArray2[num31, num32] = num33; } } } double[,] numArray3 = new double[columnCount + 1, columnCount + 2]; double[] numArray4 = new double[columnCount + 2]; double[,] numArray5 = flag2 ? ((double[, ]) new double[columnCount + 1, columnCount + 1]) : null; for (int k = 0; k < rowCount; k++) { numArray4[columnCount + 1] += numArray[k] * numArray[k]; numArray3[0, columnCount + 1] += numArray[k]; numArray4[0] = numArray3[0, columnCount + 1]; for (int num35 = 0; num35 < columnCount; num35++) { numArray3[0, num35 + 1] += numArray2[k, num35]; numArray3[num35 + 1, 0] = numArray3[0, num35 + 1]; numArray3[num35 + 1, columnCount + 1] += numArray2[k, num35] * numArray[k]; numArray4[num35 + 1] = numArray3[num35 + 1, columnCount + 1]; for (int num36 = num35; num36 < columnCount; num36++) { numArray3[num36 + 1, num35 + 1] += numArray2[k, num35] * numArray2[k, num36]; numArray3[num35 + 1, num36 + 1] = numArray3[num36 + 1, num35 + 1]; } } } numArray3[0, 0] = rowCount; if (flag2) { for (int num37 = 0; num37 < (columnCount + 1); num37++) { numArray5[num37, num37] = 1.0; } } if (flag) { for (int num38 = 0; num38 < (columnCount + 1); num38++) { if (numArray3[num38, num38] == 0.0) { bool flag3 = false; for (int num39 = num38 + 1; !flag3 && (num39 < (columnCount + 1)); num39++) { if (numArray3[num39, num38] != 0.0) { for (int num40 = 0; num40 < (columnCount + 2); num40++) { double num41 = numArray3[num38, num40]; numArray3[num38, num40] = numArray3[num39, num40]; numArray3[num39, num40] = num41; } if (flag2) { for (int num42 = 0; num42 < (columnCount + 1); num42++) { double num43 = numArray5[num38, num42]; numArray5[num38, num42] = numArray5[num39, num42]; numArray5[num39, num42] = num43; } } flag3 = true; } } if (!flag3) { return(CalcErrors.Number); } } double num44 = 1.0 / numArray3[num38, num38]; for (int num45 = 0; num45 < (columnCount + 2); num45++) { numArray3[num38, num45] *= num44; } if (flag2) { for (int num46 = 0; num46 < (columnCount + 1); num46++) { numArray5[num38, num46] *= num44; } } for (int num47 = 0; num47 < (columnCount + 1); num47++) { if (num47 != num38) { num44 = -numArray3[num47, num38]; for (int num48 = 0; num48 < (columnCount + 2); num48++) { numArray3[num47, num48] += num44 * numArray3[num38, num48]; } if (flag2) { for (int num49 = 0; num49 < (columnCount + 1); num49++) { numArray5[num47, num49] += num44 * numArray5[num38, num49]; } } } } } } else { for (int num50 = 1; num50 < (columnCount + 1); num50++) { if (numArray3[num50, num50] == 0.0) { bool flag4 = false; for (int num51 = num50 + 1; !flag4 && (num51 < (columnCount + 1)); num51++) { if (numArray3[num51, num50] != 0.0) { for (int num52 = 0; num52 < (columnCount + 2); num52++) { double num53 = numArray3[num50, num52]; numArray3[num50, num52] = numArray3[num51, num52]; numArray3[num51, num52] = num53; } if (flag2) { for (int num54 = 0; num54 < (columnCount + 1); num54++) { double num55 = numArray5[num50, num54]; numArray5[num50, num54] = numArray5[num51, num54]; numArray5[num51, num54] = num55; } } flag4 = true; } } if (!flag4) { return(CalcErrors.Number); } } double num56 = 1.0 / numArray3[num50, num50]; for (int num57 = 1; num57 < (columnCount + 2); num57++) { numArray3[num50, num57] *= num56; } if (flag2) { for (int num58 = 1; num58 < (columnCount + 1); num58++) { numArray5[num50, num58] *= num56; } } for (int num59 = 1; num59 < (columnCount + 1); num59++) { if (num59 != num50) { num56 = -numArray3[num59, num50]; for (int num60 = 1; num60 < (columnCount + 2); num60++) { numArray3[num59, num60] += num56 * numArray3[num50, num60]; } if (flag2) { for (int num61 = 1; num61 < (columnCount + 1); num61++) { numArray5[num59, num61] += num56 * numArray5[num50, num61]; } } } } numArray3[0, columnCount + 1] = 0.0; } } object[,] values = new object[flag2 ? 5 : 1, columnCount + 1]; for (int m = 0; m < (columnCount + 1); m++) { values[0, m] = (double)numArray3[columnCount - m, columnCount + 1]; } if (flag2) { double num64 = numArray4[columnCount + 1] - ((numArray4[0] * numArray4[0]) / ((double)rowCount)); double num63 = numArray4[columnCount + 1]; for (int num66 = 0; num66 < (columnCount + 1); num66++) { num63 -= numArray3[num66, columnCount + 1] * numArray4[num66]; } double num65 = num64 - num63; if (num64 == 0.0) { values[2, 0] = CalcErrors.Number; } else { values[2, 0] = num65 / num64; } values[4, 0] = (double)num65; values[4, 1] = (double)num63; if (flag) { if (((rowCount - columnCount) - 1) == 0) { values[2, 1] = CalcErrors.Number; for (int num67 = 0; num67 < (columnCount + 1); num67++) { values[1, num67] = CalcErrors.Number; } } else { double d = num63 / ((double)((rowCount - columnCount) - 1)); for (int num69 = 0; num69 < (columnCount + 1); num69++) { values[1, columnCount - num69] = (double)Math.Sqrt(d * numArray5[num69, num69]); } values[2, 1] = (double)Math.Sqrt(d); } if (num63 == 0.0) { values[3, 0] = CalcErrors.Number; } else { values[3, 0] = (((rowCount - columnCount) - 1) * num65) / (num63 * columnCount); } values[3, 1] = (rowCount - columnCount) - 1; } else { if ((rowCount - columnCount) == 0) { for (int num70 = 0; num70 < (columnCount + 1); num70++) { values[1, num70] = CalcErrors.Number; } values[2, 1] = CalcErrors.Number; } else { double num71 = num63 / ((double)(rowCount - columnCount)); values[1, columnCount] = CalcErrors.NotAvailable; for (int num72 = 1; num72 < (columnCount + 1); num72++) { values[1, columnCount - num72] = (double)Math.Sqrt(num71 * numArray5[num72, num72]); } values[2, 1] = (double)Math.Sqrt(num71); } if (num63 == 0.0) { values[3, 0] = CalcErrors.Number; } else { values[3, 0] = ((rowCount - columnCount) * num65) / (num63 * columnCount); } values[3, 1] = rowCount - columnCount; } for (int num73 = 2; num73 < 5; num73++) { for (int num74 = 2; num74 < (columnCount + 1); num74++) { values[num73, num74] = CalcErrors.NotAvailable; } } } return(new ConcreteArray(values)); }
public static double TREND(ICalcEvaluator evaluator, object[,] values, object[,] indexes, int dest) { CalcArray array = evaluator.EvaluateFunction(new CalcTrendFunction(), new object[] { values, indexes, (int)dest }) as CalcArray; return((double)((double)array.GetValue(0, 0))); }
public static double FORECAST(ICalcEvaluator evaluator, int dest, object[,] values, object[,] indexes) { CalcArray array = evaluator.EvaluateFunction(new CalcForecastFunction(), new object[] { (int)dest, values, indexes }) as CalcArray; return((double)((double)array.GetValue(0, 0))); }
/// <summary> /// Returns the matrix product of two arrays. /// </summary> /// <param name="args"><para> /// The args contains 2 items: array1, array2. /// </para> /// <para> /// Array1, array2 are the arrays you want to multiply. /// </para></param> /// <returns> /// A <see cref="T:System.Double" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); CalcArray array = CalcConvert.ToArray(args[0]); CalcArray array2 = CalcConvert.ToArray(args[1]); int rowCount = array.RowCount; int columnCount = array.ColumnCount; int num3 = array2.RowCount; int num4 = array2.ColumnCount; if (columnCount != num3) { return(CalcErrors.Value); } double[,] numArray = new double[rowCount, columnCount]; double[,] numArray2 = new double[num3, num4]; double[,] values = new double[rowCount, num4]; for (int i = 0; i < rowCount; i++) { for (int m = 0; m < columnCount; m++) { object obj2 = array.GetValue(i, m); if (CalcConvert.IsError(obj2)) { return(obj2); } if (!CalcConvert.IsNumber(obj2)) { return(CalcErrors.Value); } numArray[i, m] = CalcConvert.ToDouble(obj2); } } for (int j = 0; j < num3; j++) { for (int n = 0; n < num4; n++) { object obj3 = array2.GetValue(j, n); if (CalcConvert.IsError(obj3)) { return(obj3); } if (!CalcConvert.IsNumber(obj3)) { return(CalcErrors.Value); } numArray2[j, n] = CalcConvert.ToDouble(obj3); } } for (int k = 0; k < rowCount; k++) { for (int num10 = 0; num10 < num4; num10++) { double num11 = 0.0; for (int num12 = 0; num12 < num3; num12++) { num11 += numArray[k, num12] * numArray2[num12, num10]; } values[k, num10] = num11; } } return(new ConcreteArray <double>(values)); }
/// <summary> /// Returns the matrix determinant of an array. /// </summary> /// <param name="args"><para> /// The args contains 1 item: array. /// </para> /// <para> /// Array is a numeric array with an equal number of rows and columns. /// </para></param> /// <returns> /// A <see cref="T:System.Double" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); CalcArray array = CalcConvert.ToArray(args[0]); if (array.RowCount != array.ColumnCount) { return(CalcErrors.Value); } int rowCount = array.RowCount; double[,] numArray = new double[rowCount, rowCount]; for (int i = 0; i < rowCount; i++) { for (int m = 0; m < rowCount; m++) { object obj2 = array.GetValue(i, m); if (CalcConvert.IsError(obj2)) { return(obj2); } if (!CalcConvert.IsNumber(obj2)) { return(CalcErrors.Value); } numArray[i, m] = CalcConvert.ToDouble(obj2); } } double num4 = 1.0; for (int j = 0; j < (rowCount - 1); j++) { if (numArray[j, j] == 0.0) { bool flag = false; for (int num6 = j + 1; !flag && (num6 < rowCount); num6++) { if (numArray[num6, j] != 0.0) { for (int num7 = j; num7 < rowCount; num7++) { double num8 = numArray[j, num7]; numArray[j, num7] = numArray[num6, num7]; numArray[num6, num7] = num8; } num4 *= -1.0; flag = true; } } if (!flag) { return((double)0.0); } } for (int n = j + 1; n < rowCount; n++) { if (numArray[n, j] != 0.0) { double num10 = numArray[n, j] / numArray[j, j]; for (int num11 = j; num11 < rowCount; num11++) { numArray[n, num11] -= num10 * numArray[j, num11]; } } } } for (int k = 0; k < rowCount; k++) { num4 *= numArray[k, k]; } return((double)num4); }
/// <summary> /// Returns the <see cref="T:Dt.CalcEngine.CalcArray" /> predicted exponential growth by using existing data. /// </summary> /// <param name="args"><para> /// The args contains 1 - 4 items: known_y's, [known_x's], [new_x's], [const]. /// </para> /// <para> /// Known_y's is the set of y-values you already know in the relationship y = b*m^x. /// </para> /// <para> /// Known_x's is an optional set of x-values that you may already know in the relationship y = b*m^x. /// </para> /// <para> /// New_x's are new x-values for which you want GROWTH to return corresponding y-values. /// </para> /// <para> /// Const is a logical value specifying whether to force the constant b to equal 1. /// </para></param> /// <returns> /// A <see cref="T:Dt.CalcEngine.CalcArray" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { int rowCount; int columnCount; double[] numArray2; double[,] numArray3; base.CheckArgumentsLength(args); CalcArray array = CalcConvert.ToArray(args[0]); CalcArray array2 = CalcHelper.ArgumentExists(args, 1) ? CalcConvert.ToArray(args[1]) : new DefaultKnownX(array.RowCount, array.ColumnCount); CalcArray array3 = CalcHelper.ArgumentExists(args, 2) ? CalcConvert.ToArray(args[2]) : array2; bool flag = CalcHelper.ArgumentExists(args, 3) ? CalcConvert.ToBool(args[3]) : true; for (int i = 0; i < array.RowCount; i++) { for (int num2 = 0; num2 < array.ColumnCount; num2++) { object obj2 = array.GetValue(i, num2); if (obj2 is CalcError) { return(obj2); } if (!CalcConvert.IsNumber(obj2)) { return(CalcErrors.Value); } if (CalcConvert.ToDouble(obj2) <= 0.0) { return(CalcErrors.Number); } } } for (int j = 0; j < array2.RowCount; j++) { for (int num4 = 0; num4 < array2.ColumnCount; num4++) { object obj3 = array2.GetValue(j, num4); if (obj3 is CalcError) { return(obj3); } if (!CalcConvert.IsNumber(obj3)) { return(CalcErrors.Value); } } } for (int k = 0; k < array3.RowCount; k++) { for (int num6 = 0; num6 < array3.ColumnCount; num6++) { object obj4 = array3.GetValue(k, num6); if (obj4 is CalcError) { return(obj4); } if (!CalcConvert.IsNumber(obj4)) { return(CalcErrors.Value); } } } if ((array.RowCount == array2.RowCount) && (array.ColumnCount == array2.ColumnCount)) { double num12; double num13; double num7 = array2.RowCount * array2.ColumnCount; double num8 = 0.0; double num9 = 0.0; double num10 = 0.0; double num11 = 0.0; for (int num14 = 0; num14 < array2.RowCount; num14++) { for (int num15 = 0; num15 < array2.ColumnCount; num15++) { double num16; double num17; if (!CalcConvert.TryToDouble(array2.GetValue(num14, num15), out num16, true) || !CalcConvert.TryToDouble(array.GetValue(num14, num15), out num17, true)) { return(CalcErrors.Value); } num17 = Math.Log(num17); num8 += num16; num9 += num16 * num16; num10 += num17; num11 += num16 * num17; } } if (flag) { num12 = ((num7 * num11) - (num8 * num10)) / ((num7 * num9) - (num8 * num8)); num13 = ((num10 * num9) - (num8 * num11)) / ((num7 * num9) - (num8 * num8)); } else { num12 = num11 / num9; num13 = 0.0; } double[,] numArray = new double[array3.RowCount, array3.ColumnCount]; for (int num18 = 0; num18 < array3.RowCount; num18++) { for (int num19 = 0; num19 < array3.ColumnCount; num19++) { double num20; if (!CalcConvert.TryToDouble(array3.GetValue(num18, num19), out num20, true)) { return(CalcErrors.Value); } numArray[num18, num19] = Math.Exp((num12 * num20) + num13); } } return(new ConcreteArray(numArray)); } if (((array.ColumnCount != 1) || (array.RowCount != array2.RowCount)) && ((array.RowCount != 1) || (array.ColumnCount != array2.ColumnCount))) { return(CalcErrors.NotAvailable); } if (array.ColumnCount == 1) { rowCount = array2.RowCount; columnCount = array2.ColumnCount; numArray3 = new double[rowCount, columnCount]; numArray2 = new double[rowCount]; for (int num23 = 0; num23 < rowCount; num23++) { double num24; if (!CalcConvert.TryToDouble(array.GetValue(num23, 0), out num24, true)) { return(CalcErrors.Value); } numArray2[num23] = Math.Log(num24); } for (int num25 = 0; num25 < rowCount; num25++) { for (int num26 = 0; num26 < columnCount; num26++) { double num27; if (!CalcConvert.TryToDouble(array2.GetValue(num25, num26), out num27, true)) { return(CalcErrors.Value); } numArray3[num25, num26] = num27; } } } else { rowCount = array2.ColumnCount; columnCount = array2.RowCount; numArray3 = new double[rowCount, columnCount]; numArray2 = new double[rowCount]; for (int num28 = 0; num28 < rowCount; num28++) { double num29; if (!CalcConvert.TryToDouble(array.GetValue(0, num28), out num29, true)) { return(CalcErrors.Value); } numArray2[num28] = num29; } for (int num30 = 0; num30 < rowCount; num30++) { for (int num31 = 0; num31 < columnCount; num31++) { double num32; if (!CalcConvert.TryToDouble(array2.GetValue(num31, num30), out num32, true)) { return(CalcErrors.Value); } numArray3[num30, num31] = num32; } } } double[,] numArray4 = new double[columnCount + 1, columnCount + 2]; double[] numArray5 = new double[columnCount + 2]; for (int m = 0; m < rowCount; m++) { numArray5[columnCount + 1] += numArray2[m] * numArray2[m]; numArray4[0, columnCount + 1] += numArray2[m]; numArray5[0] = numArray4[0, columnCount + 1]; for (int num34 = 0; num34 < columnCount; num34++) { numArray4[0, num34 + 1] += numArray3[m, num34]; numArray4[num34 + 1, 0] = numArray4[0, num34 + 1]; numArray4[num34 + 1, columnCount + 1] += numArray3[m, num34] * numArray2[m]; numArray5[num34 + 1] = numArray4[num34 + 1, columnCount + 1]; for (int num35 = num34; num35 < columnCount; num35++) { numArray4[num35 + 1, num34 + 1] += numArray3[m, num34] * numArray3[m, num35]; numArray4[num34 + 1, num35 + 1] = numArray4[num35 + 1, num34 + 1]; } } } numArray4[0, 0] = rowCount; if (flag) { for (int num36 = 0; num36 < (columnCount + 1); num36++) { double num38; int num37 = num36; while ((num37 < (columnCount + 1)) && (numArray4[num37, num36] == 0.0)) { num37++; } if (num37 >= (columnCount + 1)) { return(CalcErrors.NotAvailable); } for (int num39 = 0; num39 < (columnCount + 2); num39++) { num38 = numArray4[num36, num39]; numArray4[num36, num39] = numArray4[num37, num39]; numArray4[num37, num39] = num38; } num38 = 1.0 / numArray4[num36, num36]; for (int num40 = 0; num40 < (columnCount + 2); num40++) { numArray4[num36, num40] *= num38; } for (num37 = 0; num37 < (columnCount + 1); num37++) { if (num37 != num36) { num38 = -numArray4[num37, num36]; for (int num41 = 0; num41 < (columnCount + 2); num41++) { numArray4[num37, num41] += num38 * numArray4[num36, num41]; } } } } } else { for (int num42 = 1; num42 < (columnCount + 1); num42++) { double num44; int num43 = num42; while ((num43 < (columnCount + 1)) && (numArray4[num43, num42] == 0.0)) { num43++; } if (num43 >= (columnCount + 1)) { return(CalcErrors.NotAvailable); } for (int num45 = 1; num45 < (columnCount + 2); num45++) { num44 = numArray4[num42, num45]; numArray4[num42, num45] = numArray4[num43, num45]; numArray4[num43, num45] = num44; } num44 = 1.0 / numArray4[num42, num42]; for (int num46 = 1; num46 < (columnCount + 2); num46++) { numArray4[num42, num46] *= num44; } for (num43 = 1; num43 < (columnCount + 1); num43++) { if (num43 != num42) { num44 = -numArray4[num43, num42]; for (int num47 = 1; num47 < (columnCount + 2); num47++) { numArray4[num43, num47] += num44 * numArray4[num42, num47]; } } } numArray4[0, columnCount + 1] = 0.0; } } if (array.ColumnCount == 1) { double[,] numArray6 = new double[array3.RowCount, 1]; for (int num48 = 0; num48 < array3.RowCount; num48++) { double d = numArray4[0, columnCount + 1]; for (int num50 = 0; num50 < columnCount; num50++) { double num51; if (!CalcConvert.TryToDouble(array3.GetValue(num48, num50), out num51, true)) { return(CalcErrors.Value); } d += numArray4[num50 + 1, columnCount + 1] * num51; } numArray6[num48, 0] = Math.Exp(d); } return(new ConcreteArray(numArray6)); } double[,] values = new double[1, array3.ColumnCount]; for (int n = 0; n < array3.ColumnCount; n++) { double num53 = numArray4[0, columnCount + 1]; for (int num54 = 0; num54 < columnCount; num54++) { double num55; if (!CalcConvert.TryToDouble(array3.GetValue(num54, n), out num55, true)) { return(CalcErrors.Value); } num53 += numArray4[num54 + 1, columnCount + 1] * num55; } values[0, n] = Math.Exp(num53); } return(new ConcreteArray(values)); }
/// <summary> /// Returns the inverse matrix for the matrix stored in an array. /// </summary> /// <param name="args"><para> /// The args contains 1 item: array. /// </para> /// <para> /// Array is a numeric array with an equal number of rows and columns. /// </para></param> /// <returns> /// A <see cref="T:System.Double" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); CalcArray array = CalcConvert.ToArray(args[0]); if (array.RowCount != array.ColumnCount) { return(CalcErrors.Value); } int rowCount = array.RowCount; double[,] numArray = new double[rowCount, rowCount]; double[,] values = new double[rowCount, rowCount]; for (int i = 0; i < rowCount; i++) { for (int n = 0; n < rowCount; n++) { object obj2 = array.GetValue(i, n); if (CalcConvert.IsError(obj2)) { return(obj2); } if (!CalcConvert.IsNumber(obj2)) { return(CalcErrors.Value); } numArray[i, n] = CalcConvert.ToDouble(obj2); } } for (int j = 0; j < rowCount; j++) { for (int num5 = 0; num5 < rowCount; num5++) { values[j, num5] = (j == num5) ? 1.0 : 0.0; } } for (int k = 0; k < rowCount; k++) { if (numArray[k, k] == 0.0) { bool flag = false; for (int num7 = k + 1; !flag && (num7 < rowCount); num7++) { if (numArray[num7, k] != 0.0) { for (int num8 = k; num8 < rowCount; num8++) { double num9 = numArray[k, num8]; numArray[k, num8] = numArray[num7, num8]; numArray[num7, num8] = num9; } for (int num10 = 1; num10 < rowCount; num10++) { double num11 = values[k, num10]; values[k, num10] = values[num7, num10]; values[num7, num10] = num11; } flag = true; } } if (!flag) { return(CalcErrors.Number); } } for (int num12 = 0; num12 < rowCount; num12++) { if ((num12 != k) && (numArray[num12, k] != 0.0)) { double num13 = numArray[num12, k] / numArray[k, k]; for (int num14 = k; num14 < rowCount; num14++) { numArray[num12, num14] -= num13 * numArray[k, num14]; } for (int num15 = 0; num15 < rowCount; num15++) { values[num12, num15] -= num13 * values[k, num15]; } } } } for (int m = 0; m < rowCount; m++) { double num17 = numArray[m, m]; for (int num18 = 0; num18 < rowCount; num18++) { values[m, num18] /= num17; } } return(new ConcreteArray <double>(values)); }
/// <summary> /// Returns an <see cref="T:Dt.CalcEngine.CalcArray" /> array of y-values along a linear trend. /// </summary> /// <param name="args"><para> /// The args contains 1 - 4 items: known_y's, [known_x's], [new_x's], [const]. /// </para> /// <para> /// Known_y's is the set of y-values you already know in the relationship y = mx + b. /// </para> /// <para> /// Known_x's is an optional set of x-values that you may already know in the relationship y = mx + b. /// </para> /// <para> /// New_x's are new x-values for which you want TREND to return corresponding y-values. /// </para> /// <para> /// Const is a logical value specifying whether to force the constant b to equal 0. /// </para></param> /// <returns> /// A <see cref="T:Dt.CalcEngine.CalcArray" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { int rowCount; int columnCount; double[] numArray2; double[,] numArray3; base.CheckArgumentsLength(args); CalcArray array = CalcConvert.ToArray(args[0]); CalcArray array2 = CalcHelper.ArgumentExists(args, 1) ? CalcConvert.ToArray(args[1]) : new DefaultKnownX(array.RowCount, array.ColumnCount); CalcArray array3 = CalcHelper.ArgumentExists(args, 2) ? CalcConvert.ToArray(args[2]) : array2; bool flag = CalcHelper.ArgumentExists(args, 3) ? CalcConvert.ToBool(args[3]) : true; for (int i = 0; i < array.RowCount; i++) { for (int num2 = 0; num2 < array.ColumnCount; num2++) { if (!CalcConvert.IsNumber(array.GetValue(i, num2))) { return(CalcErrors.Value); } } } for (int j = 0; j < array2.RowCount; j++) { for (int num4 = 0; num4 < array2.ColumnCount; num4++) { if (!CalcConvert.IsNumber(array2.GetValue(j, num4))) { return(CalcErrors.Value); } } } for (int k = 0; k < array3.RowCount; k++) { for (int num6 = 0; num6 < array3.ColumnCount; num6++) { if (!CalcConvert.IsNumber(array3.GetValue(k, num6))) { return(CalcErrors.Value); } } } if ((array.RowCount == array2.RowCount) && (array.ColumnCount == array2.ColumnCount)) { double num12; double num13; double num7 = array2.RowCount * array2.ColumnCount; double num8 = 0.0; double num9 = 0.0; double num10 = 0.0; double num11 = 0.0; for (int num14 = 0; num14 < array2.RowCount; num14++) { for (int num15 = 0; num15 < array2.ColumnCount; num15++) { double num16; double num17; if (!CalcConvert.TryToDouble(array2.GetValue(num14, num15), out num16, true) || !CalcConvert.TryToDouble(array.GetValue(num14, num15), out num17, true)) { return(CalcErrors.Value); } num8 += num16; num9 += num16 * num16; num10 += num17; num11 += num16 * num17; } } if (flag) { num12 = ((num7 * num11) - (num8 * num10)) / ((num7 * num9) - (num8 * num8)); num13 = ((num10 * num9) - (num8 * num11)) / ((num7 * num9) - (num8 * num8)); } else { num12 = num11 / num9; num13 = 0.0; } double[,] numArray = new double[array3.RowCount, array3.ColumnCount]; for (int num18 = 0; num18 < array3.RowCount; num18++) { for (int num19 = 0; num19 < array3.ColumnCount; num19++) { double num20; if (!CalcConvert.TryToDouble(array3.GetValue(num18, num19), out num20, true)) { return(CalcErrors.Value); } numArray[num18, num19] = (num12 * num20) + num13; } } return(new ConcreteArray(numArray)); } if (((array.ColumnCount != 1) || (array.RowCount != array2.RowCount)) && ((array.RowCount != 1) || (array.ColumnCount != array2.ColumnCount))) { return(CalcErrors.NotAvailable); } if (array.ColumnCount == 1) { rowCount = array2.RowCount; columnCount = array2.ColumnCount; numArray3 = new double[rowCount, columnCount]; numArray2 = new double[rowCount]; for (int num23 = 0; num23 < rowCount; num23++) { double num24; if (!CalcConvert.TryToDouble(array.GetValue(num23, 0), out num24, true)) { return(CalcErrors.Value); } numArray2[num23] = num24; } for (int num25 = 0; num25 < rowCount; num25++) { for (int num26 = 0; num26 < columnCount; num26++) { double num27; if (!CalcConvert.TryToDouble(array2.GetValue(num25, num26), out num27, true)) { return(CalcErrors.Value); } numArray3[num25, num26] = num27; } } } else { rowCount = array2.ColumnCount; columnCount = array2.RowCount; numArray3 = new double[rowCount, columnCount]; numArray2 = new double[rowCount]; for (int num28 = 0; num28 < rowCount; num28++) { double num29; if (!CalcConvert.TryToDouble(array.GetValue(0, num28), out num29, true)) { return(CalcErrors.Value); } numArray2[num28] = num29; } for (int num30 = 0; num30 < rowCount; num30++) { for (int num31 = 0; num31 < columnCount; num31++) { double num32; if (!CalcConvert.TryToDouble(array2.GetValue(num31, num30), out num32, true)) { return(CalcErrors.Value); } numArray3[num30, num31] = num32; } } } double[,] numArray4 = new double[columnCount + 1, columnCount + 2]; for (int m = 0; m < rowCount; m++) { numArray4[0, columnCount + 1] += numArray2[m]; for (int num34 = 0; num34 < columnCount; num34++) { numArray4[0, num34 + 1] += numArray3[m, num34]; numArray4[num34 + 1, 0] = numArray4[0, num34 + 1]; numArray4[num34 + 1, columnCount + 1] += numArray3[m, num34] * numArray2[m]; for (int num35 = num34; num35 < columnCount; num35++) { numArray4[num35 + 1, num34 + 1] += numArray3[m, num34] * numArray3[m, num35]; numArray4[num34 + 1, num35 + 1] = numArray4[num35 + 1, num34 + 1]; } } } numArray4[0, 0] = rowCount; if (flag) { for (int num36 = 0; num36 < (columnCount + 1); num36++) { if (numArray4[num36, num36] == 0.0) { bool flag2 = false; for (int num37 = num36 + 1; !flag2 && (num37 < (columnCount + 1)); num37++) { if (numArray4[num37, num36] != 0.0) { for (int num38 = 0; num38 < (columnCount + 2); num38++) { double num39 = numArray4[num36, num38]; numArray4[num36, num38] = numArray4[num37, num38]; numArray4[num37, num38] = num39; } flag2 = true; } } if (!flag2) { return(CalcErrors.NotAvailable); } } double num40 = 1.0 / numArray4[num36, num36]; for (int num41 = 0; num41 < (columnCount + 2); num41++) { numArray4[num36, num41] *= num40; } for (int num42 = 0; num42 < (columnCount + 1); num42++) { if (num42 != num36) { num40 = -numArray4[num42, num36]; for (int num43 = 0; num43 < (columnCount + 2); num43++) { numArray4[num42, num43] += num40 * numArray4[num36, num43]; } } } } } else { for (int num44 = 1; num44 < (columnCount + 1); num44++) { if (numArray4[num44, num44] == 0.0) { bool flag3 = false; for (int num45 = num44 + 1; !flag3 && (num45 < (columnCount + 1)); num45++) { if (numArray4[num45, num44] != 0.0) { for (int num46 = 0; num46 < (columnCount + 2); num46++) { double num47 = numArray4[num44, num46]; numArray4[num44, num46] = numArray4[num45, num46]; numArray4[num45, num46] = num47; } flag3 = true; } } if (!flag3) { return(CalcErrors.NotAvailable); } } double num48 = 1.0 / numArray4[num44, num44]; for (int num49 = 1; num49 < (columnCount + 2); num49++) { numArray4[num44, num49] *= num48; } for (int num50 = 1; num50 < (columnCount + 1); num50++) { if (num50 != num44) { num48 = -numArray4[num50, num44]; for (int num51 = 1; num51 < (columnCount + 2); num51++) { numArray4[num50, num51] += num48 * numArray4[num44, num51]; } } } numArray4[0, columnCount + 1] = 0.0; } } if (array.ColumnCount == 1) { double[,] numArray5 = new double[array3.RowCount, 1]; for (int num52 = 0; num52 < array3.RowCount; num52++) { double num53 = numArray4[0, columnCount + 1]; for (int num54 = 0; num54 < columnCount; num54++) { double num55; if (!CalcConvert.TryToDouble(array3.GetValue(num52, num54), out num55, true)) { return(CalcErrors.Value); } num53 += numArray4[num54 + 1, columnCount + 1] * num55; } numArray5[num52, 0] = num53; } return(new ConcreteArray(numArray5)); } double[,] values = new double[1, array3.ColumnCount]; for (int n = 0; n < array3.ColumnCount; n++) { double num57 = numArray4[0, columnCount + 1]; for (int num58 = 0; num58 < columnCount; num58++) { double num59; if (!CalcConvert.TryToDouble(array3.GetValue(num58, n), out num59, true)) { return(CalcErrors.Value); } num57 += numArray4[num58 + 1, columnCount + 1] * num59; } values[0, n] = num57; } return(new ConcreteArray(values)); }