Exemplo n.º 1
0
        public static NewtonResult[][] ExecuteChunk([ActivityTrigger] ChunkOptions options, ILogger log)
        {
            var fractalOptions = options.FractalOptions;
            var element        = MathElement.Parse(fractalOptions.Expression, fractalOptions.VariableName);
            var func           = element.ToNewtonFunction(fractalOptions.Multiplicity).ToFunc();

            var result = new NewtonResult[options.MaxWidth - options.MinWidth][];

            for (var px = options.MinWidth; px < options.MaxWidth; ++px)
            {
                var x = fractalOptions.DomainSize.MinX + (fractalOptions.DomainSize.MaxX - fractalOptions.DomainSize.MinX) * px / (fractalOptions.PixelSize.Width - 1);
                result[px - options.MinWidth] = new NewtonResult[fractalOptions.PixelSize.Height];
                for (var py = 0; py < fractalOptions.PixelSize.Height; ++py)
                {
                    var y             = fractalOptions.DomainSize.MaxY - (fractalOptions.DomainSize.MaxY - fractalOptions.DomainSize.MinY) * py / (fractalOptions.PixelSize.Height - 1);
                    var newtonOptions = new NewtonOptions
                    {
                        Precision     = fractalOptions.Precision,
                        StartingPoint = new Complex(x, y),
                        MaxIterations = fractalOptions.MaxIterations,
                    };
                    result[px - options.MinWidth][py] = MathUtils.NewtonMethod(func, newtonOptions);
                }
            }

            return(result);
        }
        protected FractalGenerator(FractalOptions options)
        {
            Options = options;
            var element = MathElement.Parse(Options.Expression, Options.VariableName);

            Function = element.ToNewtonFunction(Options.Multiplicity).ToFunc();
        }
Exemplo n.º 3
0
        public string CanDerive(string expression)
        {
            var element = MathElement.Parse(expression);
            var derived = element.Derive();

            return(derived.ToString());
        }
Exemplo n.º 4
0
        public string CanSimplify(string expression)
        {
            var original = MathElement.Parse(expression);
            var actual   = original.Simplify();

            return(actual.ToString());
        }
Exemplo n.º 5
0
        public void CanGenerateNewtonFunction(string expression)
        {
            var baseElement = MathElement.Parse(expression);

            // Making sure the base function can be created, since we are on it
            baseElement.ToFunc();

            var newtonElement = baseElement.ToNewtonFunction(Complex.One);

            newtonElement.ToFunc();
        }
        public MathElementControl()
        {
            Value = new MathElement();
            InitializeComponent();
            root.DataContext = this;

            Loaded += Control_Loaded;
            boxes   = new[]
            {
                main, sup, sub
            };
        }
Exemplo n.º 7
0
        /// <summary>
        /// Setups a new math element with the attributes from the token.
        /// </summary>
        /// <param name="element">The element to setup.</param>
        /// <param name="tag">The tag token to use.</param>
        /// <returns>The finished element.</returns>
        public static MathElement Setup(this MathElement element, HtmlTagToken tag)
        {
            var count = tag.Attributes.Count;

            for (var i = 0; i < count; i++)
            {
                var name  = tag.Attributes[i].Key;
                var value = tag.Attributes[i].Value;
                element.AdjustAttribute(name.AdjustToMathAttribute(), value);
            }

            return(element);
        }
Exemplo n.º 8
0
        public void CanEvaluateExpression(string expression, Complex argument, Complex expected)
        {
            // Arrange
            var element = MathElement.Parse(expression);
            var expr    = element.ToExpression();
            var func    = expr.Compile();

            // Act
            var actual = func(argument);

            // Assert
            AssertEqual(expected, actual);
        }
Exemplo n.º 9
0
        public void CanNegate(string expression)
        {
            var original = MathElement.Parse(expression);

            var copy = original.Negated();

            Assert.AreNotSame(original, copy);
            Assert.AreNotEqual(original.ToString(), copy.ToString());

            var reverted = copy.Negated();

            Assert.AreNotSame(original, reverted);
            Assert.AreEqual(original.ToString(), reverted.ToString());
        }
Exemplo n.º 10
0
        public void NewtonMethodTests(string expression, double multiplicity, double startingPoint, double expected)
        {
            // Only testing the real part, as it makes it simpler to pass compile-time
            // inputs. The outcome should be the same for complex numbers, especially
            // given that the Complex library already existed

            var element = MathElement.Parse(expression);
            var newton  = element.ToNewtonFunction(new Complex(multiplicity, 0));
            var func    = newton.ToFunc();

            var options = new NewtonOptions
            {
                MaxIterations = 50,
                Precision     = 1e-3,
                StartingPoint = new Complex(startingPoint, 0),
            };

            var result = MathUtils.NewtonMethod(func, options);

            Assert.AreEqual(expected, result.Solution.Real, 1e-2);
        }
Exemplo n.º 11
0
        public static MathMlTerm MathMLConvert(Decomposed decomposed)
        {
            var math = new MathElement();

            decomposed.Factors.ForEach(factor =>
            {
                var mfenced = new MfencedElement();
                factor.Terms.ForEach(term =>
                {
                    var operation = (term.Sign == Sign.Plus) ? "+" : "-";
                    mfenced.Terms.Add(operation);

                    mfenced.Terms.Add(term.Number);  //number

                    if (term.Symbol != null && term.Symbol != default(char))
                    {
                        var insideOperation = "&InvisibleTimes;";

                        mfenced.Terms.Add(insideOperation);  //number *

                        var insideMsup = new MsupElement();

                        var symbolicValue = term.Symbol.Value;

                        var symbolPower = term.SymbolsPower;

                        insideMsup.Terms.Add(symbolicValue);
                        insideMsup.Terms.Add(symbolPower);
                        mfenced.Terms.Add(insideMsup);//x^power
                    }
                });
                math.Terms.Add(mfenced);
            });

            return(math);
        }
Exemplo n.º 12
0
        public string CanFormatExpression(string expression)
        {
            var element = MathElement.Parse(expression);

            return(element.ToString());
        }
Exemplo n.º 13
0
 public void CanDetectMalformedExpressions(string expression)
 {
     Assert.Throws <ParseException>(() => MathElement.Parse(expression));
 }
Exemplo n.º 14
0
 public void AddNode(MathElement newNode)
 {
     MathElement PreviousNode = MathNodes[MathNodes.Count - 1];
 }