예제 #1
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> normal cumulative distribution.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 4 items: x, mean, standard_dev, cumulative.
        /// </para>
        /// <para>
        /// X is the value for which you want the distribution.
        /// </para>
        /// <para>
        /// Mean is the arithmetic mean of the distribution.
        /// </para>
        /// <para>
        /// Standard_dev is the standard deviation of the distribution.
        /// </para>
        /// <para>
        /// Cumulative is a logical value that determines the form of the function. If cumulative is TRUE, NORMDIST returns the cumulative distribution function; if FALSE, it returns the probability mass function.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            double num;
            double num2;
            double num3;
            bool   flag;

            base.CheckArgumentsLength(args);
            if ((!CalcConvert.TryToDouble(args[0], out num, true) || !CalcConvert.TryToDouble(args[1], out num2, true)) || !CalcConvert.TryToDouble(args[2], out num3, true))
            {
                return(CalcErrors.Value);
            }
            if (!CalcConvert.TryToBool(args[3], out flag))
            {
                return(CalcErrors.Value);
            }
            if (num3 <= 0.0)
            {
                return(CalcErrors.Number);
            }
            if (flag)
            {
                CalcBuiltinFunction function = new CalcNormSDistFunction();
                object[]            objArray = new object[] { (double)((num - num2) / num3) };
                return(function.Evaluate(objArray));
            }
            return(CalcConvert.ToResult(Math.Exp(-((num - num2) * (num - num2)) / ((2.0 * num3) * num3)) / (Math.Sqrt(6.2831853071795862) * num3)));
        }
예제 #2
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> error function integrated between lower_limit and upper_limit.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 - 2 items: lower_limit, [upper_limit].
        /// </para>
        /// <para>
        /// Lower_limit is the lower bound for integrating ERF.
        /// </para>
        /// <para>
        /// Upper_limit is the upper bound for integrating ERF.
        /// If omitted, ERF integrates between zero and lower_limit.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            double num;

            base.CheckArgumentsLength(args);
            if (!CalcConvert.TryToDouble(args[0], out num, true))
            {
                return(CalcErrors.Value);
            }
            double number = 0.0;

            if (CalcHelper.ArgumentExists(args, 1) && !CalcConvert.TryToDouble(args[1], out number, true))
            {
                return(CalcErrors.Value);
            }
            if ((num < 0.0) || (number < 0.0))
            {
                return(CalcErrors.Number);
            }
            if ((num > 27.0) || (number > 27.0))
            {
                return(CalcErrors.Number);
            }
            CalcBuiltinFunction function = new CalcNormSDistFunction();
            object obj2 = function.Evaluate(new object[] { (double)(num * Math.Sqrt(2.0)) });

            if (obj2 is CalcError)
            {
                return((double)double.NaN);
            }
            double num3 = (((double)obj2) * 2.0) - 1.0;

            if (CalcHelper.ArgumentExists(args, 1))
            {
                obj2 = function.Evaluate(new object[] { (double)(number * Math.Sqrt(2.0)) });
                if (obj2 is CalcError)
                {
                    return((double)double.NaN);
                }
                double num4 = (((double)obj2) * 2.0) - 1.0;
                num3 = num4 - num3;
            }
            return((double)num3);
        }
예제 #3
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> cumulative lognormal distribution of x, where ln(x) is normally distributed with parameters mean and standard_dev.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 3 items: x, mean, standard_dev.
        /// </para>
        /// <para>
        /// X is the value at which to evaluate the function.
        /// </para>
        /// <para>
        /// Mean is the mean of ln(x).
        /// </para>
        /// <para>
        /// Standard_dev is the standard deviation of ln(x).
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            double num;
            double num2;
            double num3;

            base.CheckArgumentsLength(args);
            if ((!CalcConvert.TryToDouble(args[0], out num, true) || !CalcConvert.TryToDouble(args[1], out num2, true)) || !CalcConvert.TryToDouble(args[2], out num3, true))
            {
                return(CalcErrors.Value);
            }
            if ((num <= 0.0) || (num3 <= 0.0))
            {
                return(CalcErrors.Number);
            }
            CalcBuiltinFunction function = new CalcNormSDistFunction();

            return(function.Evaluate(new object[] { (double)((Math.Log(num) - num2) / num3) }));
        }
예제 #4
0
        /// <summary>
        /// Returns the one-tailed probability-value of a z-test.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 2 - 3 items: array, ¦Ì0, [sigma].
        /// </para>
        /// <para>
        /// Array is the array or range of data against which to test ¦Ì0.
        /// </para>
        /// <para>
        /// ¦Ì0  is the value to test.
        /// </para>
        /// <para>
        /// [Sigma] is the population (known) standard deviation. If omitted,
        /// the sample standard deviation is used.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Object" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            double num;

            base.CheckArgumentsLength(args);
            if (!CalcConvert.TryToDouble(args[1], out num, true))
            {
                return(CalcErrors.Value);
            }
            double number = 0.0;

            if (CalcHelper.ArgumentExists(args, 2) && !CalcConvert.TryToDouble(args[2], out number, true))
            {
                return(CalcErrors.Value);
            }
            double num3 = 0.0;
            double num4 = 0.0;
            int    num7 = 0;

            if (ArrayHelper.IsArrayOrRange(args[0]))
            {
                for (int i = 0; i < ArrayHelper.GetLength(args[0], 0); i++)
                {
                    object obj2 = ArrayHelper.GetValue(args[0], i, 0);
                    if (CalcConvert.IsNumber(obj2))
                    {
                        double num9 = CalcConvert.ToDouble(obj2);
                        num3 += num9;
                        num4 += num9 * num9;
                        num7++;
                    }
                    else if (obj2 is CalcError)
                    {
                        return(obj2);
                    }
                }
            }
            else
            {
                double num10;
                if (!CalcConvert.TryToDouble(args[0], out num10, true))
                {
                    return(CalcErrors.Value);
                }
                num3 += num10;
                num4 += num10 * num10;
                num7++;
            }
            switch (num7)
            {
            case 0:
                return(CalcErrors.NotAvailable);

            case 1:
                return(CalcErrors.DivideByZero);
            }
            double num5 = num3 / ((double)num7);
            double num6 = CalcHelper.ArgumentExists(args, 2) ? number : Math.Sqrt(((num7 * num4) - (num3 * num3)) / ((double)(num7 * (num7 - 1))));

            if (num6 == 0.0)
            {
                return(CalcErrors.DivideByZero);
            }
            CalcNormSDistFunction function = new CalcNormSDistFunction();

            object[] objArray = new object[] { (double)((num5 - num) / (num6 / Math.Sqrt((double)num7))) };
            object   obj3     = function.Evaluate(objArray);

            if (obj3 is CalcError)
            {
                return(obj3);
            }
            return(CalcConvert.ToResult(1.0 - ((double)obj3)));
        }
예제 #5
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> one tailed probability of the chi-squared distribution.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 2 items: x, degrees_freedom.
        /// </para>
        /// <para>
        /// X is the value at which you want to evaluate the distribution.
        /// </para>
        /// <para>
        /// Degrees_freedom is the number of degrees of freedom.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            double num2;
            double num3;
            double num6;
            double num9;

            base.CheckArgumentsLength(args);
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] is CalcError)
                {
                    return(args[i]);
                }
            }
            if (!CalcConvert.TryToDouble(args[0], out num2, true) || !CalcConvert.TryToDouble(args[1], out num3, true))
            {
                return(CalcErrors.Value);
            }
            if (num2 < 0.0)
            {
                return(CalcErrors.Number);
            }
            if ((num3 < 1.0) || (num3 > Math.Pow(10.0, 10.0)))
            {
                return(CalcErrors.Number);
            }
            double num4  = Math.Log(Math.Sqrt(3.1415926535897931));
            double num5  = 1.0 / Math.Sqrt(3.1415926535897931);
            double num11 = 0.0;
            double d     = num2;
            double num10 = 0.5 * d;
            bool   flag  = (num3 % 2.0) == 0.0;

            if (num3 > 1.0)
            {
                num11 = Math.Exp(-num10);
            }
            object obj2 = new CalcNormSDistFunction().Evaluate(new object[] { (double)-Math.Sqrt(d) });

            if (obj2 is CalcError)
            {
                return(obj2);
            }
            double num13 = (double)((double)obj2);
            double num7  = flag ? num11 : (2.0 * num13);

            if (num3 <= 2.0)
            {
                return((double)num7);
            }
            d = 0.5 * (num3 - 1.0);
            double num8 = flag ? 1.0 : 0.5;

            if (num10 > 20.0)
            {
                num6 = flag ? 0.0 : num4;
                num9 = Math.Log(num10);
                while (num8 <= d)
                {
                    num6  = Math.Log(num8) + num6;
                    num7 += Math.Exp(((num9 * num8) - num10) - num6);
                    num8++;
                }
                return((double)num7);
            }
            num6 = flag ? 1.0 : (num5 / Math.Sqrt(num10));
            num9 = 0.0;
            while (num8 <= d)
            {
                num6 *= num10 / num8;
                num9 += num6;
                num8++;
            }
            return((double)((num9 * num11) + num7));
        }