Ejemplo n.º 1
0
            public static double?Limit(MonoFunctionHandler f, double precision, LimVariable point)  //返回一个一元函数在某点的左右极限值
            {
                if (f == null)
                {
                    throw new ArgumentNullException("Function Null");
                }
                double res = 0;

                precision = Math.Abs(precision);
                try
                {
                    switch (point.Sign)
                    {
                    case LimSign.Negative:
                        res = f(point.Value - precision);
                        break;

                    case LimSign.Positive:
                        res = f(point.Value + precision);
                        break;
                    }
                }
                catch (Exception) //极限不存在或其他错误
                {
                    //MessageBox
                    return(null);
                }
                return(res);
            }
Ejemplo n.º 2
0
            public static double?Derivative(MonoFunctionHandler f, LimVariable x, double precision = 1E-3)  //返回一个一元函数在某点的左右导数值;precision过大会引入较大误差,precision过小会导致数值结果不稳定
            {
                if (f == null)
                {
                    throw new ArgumentNullException("Function Null");
                }
                double res = 0;

                precision = Math.Abs(precision);
                try
                {
                    switch (x.Sign)
                    {
                    case LimSign.Negative:
                        res = (-25 * f(x.Value) + 48 * f(x.Value - precision) - 36 * f(x.Value - 2 * precision) + 16 * f(x.Value - 3 * precision) - 3 * f(x.Value - 4 * precision)) / (12 * -precision);     //五点公式
                        break;

                    case LimSign.Positive:
                        res = (-25 * f(x.Value) + 48 * f(x.Value + precision) - 36 * f(x.Value + 2 * precision) + 16 * f(x.Value + 3 * precision) - 3 * f(x.Value + 4 * precision)) / (12 * precision);
                        break;
                    }
                }
                catch (Exception) //导数不存在或其他错误
                {
                    //MessageBox
                    return(null);
                }
                return(res);
            }