Exemplo n.º 1
0
 protected override XElement VisitExponential(MethodCallExpression term, ExponentialFunction function)
 {
     return(new XElement(
                "apply",
                new XElement(((MathMLExponentialFunction)function).ToString()),
                Visit(term.Arguments[0])));
 }
        /* No encapsulo este metodo en la clase Function porque romperia con la abstracción de la clase y todas las subclases de esta heredarian este método. */
        private Function SelectFunction(string functionName, double a, double b, double c)
        {
            if (CosXFunction.GetFormula().Equals(functionName))
            {
                return(new CosXFunction(a, b));
            }
            else if (SenXFunction.GetFormula().Equals(functionName))
            {
                return(new SenXFunction(a, b));
            }
            else if (ExponentialFunction.GetFormula().Equals(functionName))
            {
                return(new ExponentialFunction(a, b));
            }
            else if (FirstGradeFunction.GetFormula().Equals(functionName))
            {
                return(new FirstGradeFunction(a, b));
            }
            else if (SecondGradeFunction.GetFormula().Equals(functionName))
            {
                return(new SecondGradeFunction(a, b, c));
            }
            else if (FractionalFunction.GetFormula().Equals(functionName))
            {
                return(new FractionalFunction(a, b));
            }

            return(null);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("GradientShade Sample:");

            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                String sOutput = "../GradientShade-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Will write new file: " + sOutput);

                Document doc      = new Document();
                Rect     pageRect = new Rect(0, 0, 792, 612);
                Page     docpage  = doc.CreatePage(Document.BeforeFirstPage, pageRect);

                Double[]            domain = { 0.0, 1.0 };
                Double[]            C0     = { 0.0, 0.0, 0.0 };
                Double[]            C1     = { 1.0, 0.0, 0.0 };
                ExponentialFunction f      = new ExponentialFunction(domain, 3, C0, C1, 1);

                Point[] coords = { new Point(72,     72),
                                   new Point(4 * 72, 72) };

                Function[]          functionList = { f };
                AxialShadingPattern asp          = new AxialShadingPattern(ColorSpace.DeviceRGB, coords, functionList);

                Path         path = new Path();
                GraphicState gs   = path.GraphicState;

                // Please note path does not create a default graphic state,
                // so this is necessary, but for the first element only.
                if (gs == null)
                {
                    gs = new GraphicState();
                }

                gs.FillColor      = new Color(asp);
                path.GraphicState = gs;

                path.MoveTo(new Point(36, 36));
                path.AddLine(new Point(36, 8 * 72 - 36));
                path.AddLine(new Point(11 * 72 - 36, 8 * 72 - 36));
                path.AddLine(new Point(11 * 72 - 36, 36));
                path.ClosePath();
                path.PaintOp = PathPaintOpFlags.Stroke | PathPaintOpFlags.Fill;

                docpage.Content.AddElement(path); // Add the new element to the Content of the page.
                docpage.UpdateContent();          // Update the PDF page with the changed content

                doc.Save(SaveFlags.Full, sOutput);
            }
        }
 public static Expression Apply(ExponentialFunction function, Expression argument)
 {
     switch(function)
     {
         case ExponentialFunction.Ln:
             return Ln(argument);
         case ExponentialFunction.Exp:
             return Exp(argument);
         default:
             return ExpressionBuilder.CallDouble(_mathType, function.ToString(), argument);
     }
 }
Exemplo n.º 5
0
        public static bool TryParse(MethodInfo method, out ExponentialFunction function)
        {
            string name = method.Name;

            if (!Enum.IsDefined(typeof(ExponentialFunction), name))
            {
                function = (ExponentialFunction)0;
                return(false);
            }

            function = (ExponentialFunction)Enum.Parse(typeof(ExponentialFunction), name);
            return(true);
        }
        /* No encapsulo este metodo en la clase Function porque romperia con la abstracción de la clase y todas las subclases de esta heredarian este método. */
        private String[] InitializeFunctionComboBox()
        {
            String[] functionList =
            {
                CosXFunction.GetFormula(),
                SenXFunction.GetFormula(),
                ExponentialFunction.GetFormula(),
                FirstGradeFunction.GetFormula(),
                SecondGradeFunction.GetFormula(),
                FractionalFunction.GetFormula()
            };

            return(functionList);
        }
Exemplo n.º 7
0
        public static Expression Apply(ExponentialFunction function, Expression argument)
        {
            switch (function)
            {
            case ExponentialFunction.Ln:
                return(Ln(argument));

            case ExponentialFunction.Exp:
                return(Exp(argument));

            default:
                return(ExpressionBuilder.CallDouble(_mathType, function.ToString(), argument));
            }
        }
        public void TestExponential()
        {
            //Arrange
            VariableNode        variableNode    = new VariableNode();
            ExponentialFunction exponentialNode = new ExponentialFunction(variableNode);

            //Act
            double result1 = exponentialNode.Calculate(0);
            double result2 = exponentialNode.Calculate(2);

            //Assert
            Assert.AreEqual(1, result1);
            Assert.AreEqual(7.3891, Math.Round(result2, 4));
        }
Exemplo n.º 9
0
        protected virtual Expression VisitExponential(MethodCallExpression term, ExponentialFunction function)
        {
            ReadOnlyCollection <Expression> newArguments = VisitExpressionList(term.Arguments);

            if (newArguments != term.Arguments)
            {
                if (newArguments.Count != 1)
                {
                    throw new InvalidOperationException("Single Argument Expected.");
                }

                return(Exponential.Apply(function, newArguments[0]));
            }

            return(term);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            using (Library lib = new Library())
            {
                String sOutput = "../Separation-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Writing to output " + sOutput);

                Document doc     = new Document();
                Page     page    = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72));
                Content  content = page.Content;
                Font     font    = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset);

                ColorSpace alternate = ColorSpace.DeviceRGB;

                Double[] domain        = { 0.0, 1.0 };
                int      nOutputs      = 3;
                Double[] range         = { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 };
                Double[] C0            = { 0.0, 0.0, 0.0 };
                Double[] C1            = { 1.0, 0.0, 0.0 };
                Function tintTransform = new ExponentialFunction(domain, nOutputs, C0, C1, 1.0);
                tintTransform.Range = range;

                ColorSpace   cs = new SeparationColorSpace("DLColor", alternate, tintTransform);
                GraphicState gs = new GraphicState();
                gs.FillColor = new Color(cs, new Double[] { 1.0 });

                Matrix textMatrix = new Matrix(24, 0, 0, 24,    // Set font width and height to 24 point size
                                               1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2"

                TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix);
                Text    text    = new Text();
                text.AddRun(textRun);
                content.AddElement(text);
                page.UpdateContent();

                doc.EmbedFonts();
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
        public void ToTaylorExpansion_1()
        {
            var exp = new ExponentialFunction {
                Aparam = 0.5, Bparam = 3.0
            };

            var expansion = exp.ToTaylorExpansion(5).ToList();

            expansion.Should().HaveCount(7);
            expansion.Select(s => s.PolynomialDegree).Should().ContainInOrder(0, 1, 2, 3, 4, 5, 0);
            expansion.Select(s => s.LittleODegree).Should().ContainInOrder(0, 0, 0, 0, 0, 0, 5);

            expansion[0].Coefficient.Should().BeApproximately(Math.Exp(3.0), 1e-10);
            expansion[1].Coefficient.Should().BeApproximately(0.5 * Math.Exp(3.0), 1e-10);
            expansion[2].Coefficient.Should().BeApproximately(0.25 / 2.0 * Math.Exp(3.0), 1e-10);
            expansion[3].Coefficient.Should().BeApproximately(0.125 / 6.0 * Math.Exp(3.0), 1e-10);
            expansion[4].Coefficient.Should().BeApproximately(0.0625 / 24.0 * Math.Exp(3.0), 1e-10);
            expansion[5].Coefficient.Should().BeApproximately(0.03125 / 120.0 * Math.Exp(3.0), 1e-10);
            expansion[6].Coefficient.Should().BeApproximately(1.0, 1e-10);
        }
 protected abstract T VisitExponential(MethodCallExpression term, ExponentialFunction function);
Exemplo n.º 13
0
 /// <summary>
 /// Calculates the exponential function for all elements.
 /// </summary>
 /// <returns></returns>
 public InstantVector Exponential()
 {
     return(AddAction(ExponentialFunction.Create()));
 }
Exemplo n.º 14
0
        public static IElementaryFunction ConvertToElementaryFunction(string str)
        {
            IElementaryFunction function = null;

            double[] arr = null;


            if (str.Contains("sin"))
            {
                function        = new Sine();
                arr             = FindParameters(str.Substring(4, str.Count() - 4));
                function.Aparam = arr[0];
                function.Bparam = arr[1];
            }
            else if (str.Contains("cos"))
            {
                function        = new Cosine();
                arr             = FindParameters(str.Substring(4, str.Count() - 4));
                function.Aparam = arr[0];
                function.Bparam = arr[1];
            }
            else if (str.Contains("ln"))
            {
                function        = new LogarithmicFunction();
                arr             = FindParameters(str.Substring(3, str.Count() - 3));
                function.Aparam = arr[0];
                function.Bparam = arr[1];
            }
            else if (str.Contains("e^"))
            {
                function        = new ExponentialFunction();
                arr             = FindParameters(str.Substring(3, str.Count() - 3));
                function.Aparam = arr[0];
                function.Bparam = arr[1];
            }
            else if (str.Contains(")^(") || str.Contains("x^(") || str.Contains(")^"))
            {
                function = new PowerFunction();


                int powerPosition = 0;

                for (int i = 0; i < str.Count(); i++)
                {
                    if (str[i] == '^')
                    {
                        powerPosition = i;
                        StringBuilder num   = new StringBuilder();
                        StringBuilder den   = new StringBuilder();
                        bool          slash = false;
                        for (int j = i + 1; j < str.Count(); j++)
                        {
                            if (str[j] != '/' && str[j] != '(' && str[j] != ')')
                            {
                                if (slash == false)
                                {
                                    num.Append(str[j]);
                                }
                                else
                                {
                                    den.Append(str[j]);
                                }
                            }
                            else if (str[j] == '/')
                            {
                                slash = true;
                            }
                        }

                        if (slash == false)
                        {
                            ((PowerFunction)function).PowerDenominator = 1;
                        }
                        else
                        {
                            ((PowerFunction)function).PowerDenominator = int.Parse(den.ToString());
                        }

                        ((PowerFunction)function).PowerNumerator = int.Parse(num.ToString());
                    }
                }

                int beginPosition = 0;

                if (str[0] == '(')
                {
                    beginPosition = 1;
                }

                arr             = FindParameters(str.Substring(beginPosition, powerPosition - beginPosition));
                function.Aparam = arr[0];
                function.Bparam = arr[1];
            }

            return(function);
        }
        protected virtual Expression VisitExponential(MethodCallExpression term, ExponentialFunction function)
        {
            ReadOnlyCollection<Expression> newArguments = VisitExpressionList(term.Arguments);
            if(newArguments != term.Arguments)
            {
                if(newArguments.Count != 1)
                {
                    throw new InvalidOperationException("Single Argument Expected.");
                }

                return Exponential.Apply(function, newArguments[0]);
            }

            return term;
        }
Exemplo n.º 16
0
        public static bool TryParse(MethodInfo method, out ExponentialFunction function)
        {
            string name = method.Name;
            if(!Enum.IsDefined(typeof(ExponentialFunction), name))
            {
                function = (ExponentialFunction)0;
                return false;
            }

            function = (ExponentialFunction)Enum.Parse(typeof(ExponentialFunction), name);
            return true;
        }
        public PointCollection[] DrawGraphic(Graphic g, double canvasWidth, double canvasHeight, FuncRect funcRect)
        {
            PointCollection points = new PointCollection();
            Polyline        graphicPolyline = new Polyline();
            double          xReal, yReal, xScreen, yScreen;

            /* Sustituyo el FuncRect real por los limites que ha introducido el usuario (en caso de que los modifique) */
            FuncRect real   = funcRect;
            FuncRect screen = DeclareFuncRect(0, canvasWidth, 0, canvasHeight);
            int      numberOfPoints = (int)screen.XMax;

            int i     = 0;
            int j     = 0;
            int limit = 0;

            if (g.Function.Formula.Equals(ExponentialFunction.GetFormula()) && g.ParamB < 0 ||
                g.Function.Formula.Equals(FractionalFunction.GetFormula()))
            {
                PointCollection[] listOfPoints = new PointCollection[2];
                while (j < 2)
                {
                    do
                    {
                        i++;
                        xReal = real.XMin + i * (real.XMax - real.XMin) / numberOfPoints;
                        yReal = g.Function.CalculateF(xReal);

                        xScreen = ConvertXFromRealToPant(xReal, screen.XMin, screen, real);
                        yScreen = ConvertYFromRealToPant(yReal, screen.YMin, screen, real);

                        points.Add(new Point(xScreen, yScreen));
                    } while (Convert.ToInt32(xReal) < limit);

                    listOfPoints[j] = points;
                    points          = new PointCollection();
                    j++;

                    xReal += 1;
                    limit  = (int)real.XMax;
                    i      = (int)(-(real.XMin) * numberOfPoints / (real.XMax - real.XMin));
                }

                return(listOfPoints);
            }
            else
            {
                PointCollection[] listOfPoints = new PointCollection[1];

                for (i = 0; i <= numberOfPoints; i++)
                {
                    xReal = real.XMin + i * (real.XMax - real.XMin) / numberOfPoints;
                    yReal = g.Function.CalculateF(xReal);

                    xScreen = ConvertXFromRealToPant(xReal, screen.XMin, screen, real);
                    yScreen = ConvertYFromRealToPant(yReal, screen.YMin, screen, real);
                    points.Add(new Point(xScreen, yScreen));
                }

                listOfPoints[0] = points;

                return(listOfPoints);
            }
        }
        static void Main(string[] args)
        {
            // ReSharper disable once UnusedVariable
            using (Library lib = new Library())
            {
                String sOutput = "Separation-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Writing to output " + sOutput);

                Document doc     = new Document();
                Page     page    = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72));
                Content  content = page.Content;
                Font     font;
                try
                {
                    font = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset);
                }
                catch (ApplicationException ex)
                {
                    if (ex.Message.Equals("The specified font could not be found.") &&
                        System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices
                                                                                       .OSPlatform.Linux) &&
                        !System.IO.Directory.Exists("/usr/share/fonts/msttcore/"))
                    {
                        Console.WriteLine("Please install Microsoft Core Fonts on Linux first.");
                        return;
                    }

                    throw;
                }

                ColorSpace alternate = ColorSpace.DeviceRGB;

                Double[] domain        = { 0.0, 1.0 };
                int      nOutputs      = 3;
                Double[] range         = { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 };
                Double[] C0            = { 0.0, 0.0, 0.0 };
                Double[] C1            = { 1.0, 0.0, 0.0 };
                Function tintTransform = new ExponentialFunction(domain, nOutputs, C0, C1, 1.0);
                tintTransform.Range = range;

                ColorSpace   cs = new SeparationColorSpace("DLColor", alternate, tintTransform);
                GraphicState gs = new GraphicState();
                gs.FillColor = new Color(cs, new[] { 1.0 });

                Matrix textMatrix = new Matrix(24, 0, 0, 24,    // Set font width and height to 24 point size
                                               1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2"

                TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix);
                Text    text    = new Text();
                text.AddRun(textRun);
                content.AddElement(text);
                page.UpdateContent();

                doc.EmbedFonts();
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
Exemplo n.º 19
0
 protected override Expression VisitExponential(MethodCallExpression methodCall, ExponentialFunction function)
 {
     throw new NotSupportedException(String.Format("Exponential function {0} is not supported.", function.ToString()));
 }
 protected override Expression VisitExponential(MethodCallExpression methodCall, ExponentialFunction function)
 {
     throw new NotSupportedException(String.Format("Exponential function {0} is not supported.", function.ToString()));
 }
 protected override T VisitExponential(MethodCallExpression term, ExponentialFunction function)
 {
     return(VisitMethodCall(term));
 }