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(); }
public string CanDerive(string expression) { var element = MathElement.Parse(expression); var derived = element.Derive(); return(derived.ToString()); }
public string CanSimplify(string expression) { var original = MathElement.Parse(expression); var actual = original.Simplify(); return(actual.ToString()); }
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 }; }
/// <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); }
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); }
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()); }
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); }
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 = "⁢"; 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); }
public string CanFormatExpression(string expression) { var element = MathElement.Parse(expression); return(element.ToString()); }
public void CanDetectMalformedExpressions(string expression) { Assert.Throws <ParseException>(() => MathElement.Parse(expression)); }
public void AddNode(MathElement newNode) { MathElement PreviousNode = MathNodes[MathNodes.Count - 1]; }