Exemple #1
0
        static void Main(string[] args)
        {
            MathLibrary.PostFixExpression a;

            string infix = "(x ^ 2) + 1 + (5/2)*";

            a = new MathLibrary.PostFixExpression();
            a.TryParsePostFixExpression(infix);
            double result = 0;

            a.TryToEvaluateForVariable("X", 1, ref result);
            Console.WriteLine("result: ", result);
        }
Exemple #2
0
        public void DrawEquation(string equation)
        {
            MathLibrary.PostFixExpression exp = new MathLibrary.PostFixExpression();
            exp.TryParsePostFixExpression(equation);

            double increment = (domainRangeMaxX - domainRangeMinX) / canvasWidth;

            double xPosition = domainRangeMinX;
            Point  lastPoint = new Point();

            while (xPosition < domainRangeMaxX)
            {
                double y = 0;
                exp.TryToEvaluateForVariable("x", xPosition, ref y);
                Point p1 = TransformToPixels(xPosition, y);
                if (IsPointInCanvas(p1) && IsPointInCanvas(lastPoint))
                {
                    graphics.DrawLine(System.Drawing.Pens.DarkRed, lastPoint, p1);
                }

                lastPoint = p1;
                xPosition = xPosition + increment;
            }
        }