Exemplo n.º 1
0
        public override MathFunction Derivative(int order)
        {
            MathFunction f = functions[0],
                         g = functions[1];

            return(new PowerFunction(1.0, f, g) * new LnFunction(1.0, f) * g.Derivative(1));
        }
        public override MathFunction Derivative(int order)
        {
            MathFunction f = functions[0],
                         g = functions[1];

            return(this * (f.Derivative(1) * g / f + new LnFunction(1.0d, f) * g.Derivative(1)));
        }
Exemplo n.º 3
0
        private void Draw(DrawingSettings drSet)
        {
            if (context == null)
            {
                return;
            }

            if (drSet.drawingObject is MathFunction)
            {
                MathFunction             func = drSet.drawingObject as MathFunction;
                Tuple <double, double>[] continuousRegions = func.ContinuousRegions(minX, maxX, minY, maxY);

                foreach (Tuple <double, double> region in continuousRegions)
                {
                    PointF[] points = PointsForFunction(func, region.Item1, region.Item2);

                    context.DrawLines(new Pen(drSet.borderColor, drSet.borderWidth), points);
                }
            }
            else if (drSet.drawingObject is GraphicsPath)
            {
                GraphicsPath path = drSet.drawingObject as GraphicsPath;

                context.FillPath(drSet.brush, path);
                context.DrawPath(new Pen(drSet.borderColor, drSet.borderWidth), path);
            }
        }
Exemplo n.º 4
0
        private PointF[] PointsForFunction(MathFunction func, double a, double b)
        {
            int count = Convert.ToInt32((b - a) / epsilan) + 1;

            PointF[] points = new PointF[Convert.ToInt32((b - a) / epsilan) + 1];
            for (int i = 0; i < count; i++)
            {
                points[i] = new PointF((float)FunctionXToScreenX(a + i * epsilan), (float)FunctionYToScreenY(func.Calculate(a + i * epsilan)));
            }

            return(points);
        }
        private double SumForIntegralApproximation(MathFunction func, double a, double b, double[] solutions, double[] coefs)
        {
            double result = 0;

            for (int i = 0; i <= powerForCoefCalculation; i++)
            {
                double x = (a + b) / 2 + (b - a) / 2 * solutions[i];
                result += coefs[i] * func.Calculate(x);
            }

            result *= (b - a) / 2;

            return(result);
        }
Exemplo n.º 6
0
        public GraphicsPath PathForFunction(MathFunction func, double a, double b)
        {
            GraphicsPath path = new GraphicsPath();

            path.StartFigure();
            path.AddLines(PointsForFunction(func, a, b));

            path.AddLine(new PointF((float)FunctionXToScreenX(b), (float)FunctionYToScreenY(func.Calculate(b))),
                         new PointF((float)FunctionXToScreenX(b), (float)FunctionYToScreenY(0)));
            path.AddLine(new PointF((float)FunctionXToScreenX(b), (float)FunctionYToScreenY(0)),
                         new PointF((float)FunctionXToScreenX(a), (float)FunctionYToScreenY(0)));
            path.CloseFigure();

            return(path);
        }
Exemplo n.º 7
0
        public void Draw(MathFunction func, Color funcColor, float width)
        {
            DrawingSettings drSet = new DrawingSettings();

            drSet.drawingObject = func;
            drSet.borderColor   = funcColor;
            drSet.borderWidth   = width;

            content.Add(drSet);

            Draw(drSet);

            if (elementToDraw != null)
            {
                elementToDraw.Image = bmp;
            }
        }
Exemplo n.º 8
0
        public GraphicsPath PathForSimpsonMethod(MathFunction func, double a, double b, int n)
        {
            GraphicsPath path = new GraphicsPath();

            double difference = (b - a) / n;

            for (int i = 0; i < n; i++)
            {
                double       x           = a + difference * i;
                MathFunction simpsonFunc = FunctionForSimpsonInterval(new PointF((float)x, (float)func.Calculate(x)),
                                                                      new PointF((float)(x + difference / 2), (float)func.Calculate(x + difference / 2)),
                                                                      new PointF((float)(x + difference), (float)func.Calculate(x + difference)));
                path.AddPath(PathForFunction(simpsonFunc, x, x + difference), false);
            }

            return(path);
        }
        public double Solve(MathFunction func, double a, double b, int n)
        {
            double result     = 0,
                   difference = (b - a) / n,
                   left       = a,
                   right      = left + difference;

            double[] solutions = SolutionsForLezandrPolynomial(powerForCoefCalculation),
            coefs = QuadratureCoefs(solutions, powerForCoefCalculation);

            for (int i = 0; i < n; i++)
            {
                result += SumForIntegralApproximation(func, left, right, solutions, coefs);
                left    = right;
                right  += difference;
            }

            return(result);
        }
        private void InitializeDivision(MathFunction[] functions)
        {
            MathFunction up  = new MathFunction(1.0d, MathFunctionType.Multiplication);
            MathFunction low = new MathFunction(1.0d, MathFunctionType.Multiplication);

            for (int i = 0; i < functions.Length; i++)
            {
                if (i % 2 == 0)
                {
                    up *= functions[i];
                }
                else
                {
                    low *= functions[i];
                }
            }

            this.functions.Add(up);
            this.functions.Add(low);
        }
        public double Solve(MathFunction func, double a, double b, int n)
        {
            if (a == b)
            {
                return(0);
            }
            if (a > b)
            {
                double tmp = a; a = b; b = tmp;
            }

            double result     = 0;
            double difference = (b - a) / n;

            for (int i = 1; i < n; i++)
            {
                result += func.Calculate(a + difference * i);
            }
            result += (func.Calculate(a) + func.Calculate(b)) / 2;
            result *= difference;

            return(result);
        }
        public double Solve(MathFunction func, double a, double b, int n)
        {
            if (a == b)
            {
                return(0);
            }
            if (a > b)
            {
                double tmp = a;
                a = b; b = tmp;
            }

            double result     = 0;
            double difference = (b - a) / n;

            for (int i = 0; i < n; i++)
            {
                result += func.Calculate(SuitableXForIndex(a + difference * i, a + difference * (i + 1)));
            }
            result *= difference;

            return(result);
        }
        private double[] SolutionsForLezandrPolynomial(int n)
        {
            MathFunction   poly   = LezandrPolynomial(n + 1);
            Equasion       eq     = new Equasion(poly, new ConstFunction(0));
            EquasionMethod method = new HalfDivision();

            double left  = -1,
                   right = -1 + 2 * epsilan;

            double[] solutions = new double[n + 1];
            int      bound     = n % 2 == 0 ? n / 2 : (n + 1) / 2;
            int      index     = 0;

            while (index < bound &&
                   left < 0)
            {
                try
                {
                    solutions[index] = method.Solve(eq, left, right);
                    left             = solutions[index] + epsilan;
                    right            = left + 2 * epsilan;
                    index++;
                } catch
                {
                    left  += 2 * epsilan;
                    right += 2 * epsilan;
                }
            }

            for (int i = 0; i < bound; i++)
            {
                solutions[n - i] = -solutions[i];
            }

            return(solutions);
        }
Exemplo n.º 14
0
        public double Solve(MathFunction func, double a, double b, int n)
        {
            if (a == b)
            {
                return(0);
            }
            if (a > b)
            {
                double tmp = a; a = b; b = tmp;
            }

            double result     = 0;
            double difference = (b - a) / (2 * n);

            for (int k = 1; k < n; k++)
            {
                result += 4 * func.Calculate(a + difference * (2 * k - 1));
                result += 2 * func.Calculate(a + difference * 2 * k);
            }
            result += 4 * func.Calculate(b - difference) + func.Calculate(a) + func.Calculate(b);
            result *= difference / 3;

            return(result);
        }
Exemplo n.º 15
0
 public Equasion(MathFunction left, MathFunction right)
 {
     this.Left  = left;
     this.Right = right;
 }
 public PowerFunction(double coef, MathFunction foundation, MathFunction power) : base()
 {
     this.coef = coef;
     functions.Add(foundation);
     functions.Add(power);
 }
Exemplo n.º 17
0
 public StepFunction(double coef, MathFunction foundation, MathFunction power) : base(coef, foundation, power)
 {
 }
        public virtual MathFunction Derivative(int order)
        {
            if (functions.Count == 0)
            {
                throw new Exception("Function is empty!");
            }

            if (order < 0)
            {
                throw new Exception("Incorrect derivative order!");
            }

            if (order == 0)
            {
                return(new MathFunction(coef, type, functions.ToArray()));
            }

            MathFunction result = 0.0d;

            switch (type)
            {
            case MathFunctionType.Sum:
                result = functions[0].Derivative(order);

                for (int i = 1; i < functions.Count; i++)
                {
                    result += functions[i].Derivative(order);
                }

                break;

            case MathFunctionType.Multiplication:
                result = new ConstFunction(0.0d);

                for (int i = 0; i < functions.Count; i++)
                {
                    MathFunction func = functions[i].Derivative(1);
                    for (int j = 0; j < functions.Count; j++)
                    {
                        if (i != j)
                        {
                            func *= functions[j];
                        }
                    }

                    result += func;
                }

                result = Derivative(order - 1);

                break;

            case MathFunctionType.Division:
                MathFunction f = functions[0],
                             g = functions[1];

                result = (f.Derivative(1) * g - g.Derivative(1) * f) / (g ^ 2);

                result = Derivative(order - 1);
                break;
            }

            return(result);
        }
        public SinFunction(double coef, MathFunction foundation) : base()
        {
            this.coef = coef;

            functions.Add(foundation);
        }