Example #1
0
 public void Replace(Dictionary <string, FloatingPoint> symbols)
 {
     foreach (var b in Table.Backend)
     {
         foreach (var i in b.Value.Backend)
         {
             Evaluate.Evaluate(symbols, i.Value);
         }
     }
 }
Example #2
0
 public static Expression Subsitute(this Expression function, string symbol, Expression value)
 {
     return(Evaluate.Evaluate(
                new Dictionary <string, FloatingPoint> {
         {
             symbol, value.ToReal()
         }
     },
                function).RealValue.ToFraction());
 }
Example #3
0
        public static double ToReal(this Expression expression, int places = 5)
        {
            var value = double.NaN;

            if (expression.IsNumber)
            {
                var empty = new Dictionary <string, FloatingPoint>();

                value = Evaluate.Evaluate(empty, expression).RealValue;
            }

            return(value.Round(places));
        }
Example #4
0
        public static void CalculateEquation(ref Dictionary <string, FloatingPoint> initialVector, int i)
        {
            var df1x = Calculus.Differentiate(x, f1);
            var df1y = Calculus.Differentiate(y, f1);
            var df2x = Calculus.Differentiate(x, f2);
            var df2y = Calculus.Differentiate(y, f2);


            double j11 = Eval.Evaluate(initialVector, df1x).RealValue;
            double j12 = Eval.Evaluate(initialVector, df1y).RealValue;
            double j21 = Eval.Evaluate(initialVector, df2x).RealValue;
            double j22 = Eval.Evaluate(initialVector, df2y).RealValue;

            if (i == 1)
            {
                Console.WriteLine("Jacobian matrix symbolic:");
                Console.WriteLine(Infix.FormatStrict(df1x) + "      " + Infix.Format(df1y) + "\n" + Infix.Format(df2x) + "     " + Infix.Format(df2y));
            }
            double[]        m        = { j11, j21, j12, j22 };
            Matrix <double> jacobian = new DenseMatrix(2, 2, m);

            Console.WriteLine("Jacobian matrix numeric:\n");
            Console.WriteLine(jacobian.ToString());
            Matrix <double> initial = new DenseMatrix(2, 1, new double[] { Eval.Evaluate(initialVector, f1).RealValue, Eval.Evaluate(initialVector, f2).RealValue });

            jacobian = jacobian.Inverse();

            var solution = jacobian * (-initial);

            var xn = x0 + solution[0, 0];
            var yn = y0 + solution[1, 0];

            var outVal = new Dictionary <string, FloatingPoint> {
                { "x", xn }, { "y", yn }
            };

            Console.WriteLine("Iteration " + i + ":\n");
            Console.WriteLine("x" + i.ToString() + " = " + xn + Environment.NewLine + "y" + i.ToString() + " = " + yn);
            Console.WriteLine("f1(x" + i + ",y" + i + ")=" + Math.Round(Eval.Evaluate(initialVector, f1).RealValue, 3));
            Console.WriteLine("f2(x" + i + ",y" + i + ")=" + Eval.Evaluate(initialVector, f2).RealValue);
            Console.WriteLine("\n");

            initialVector = outVal;
            x0            = xn;
            y0            = yn;
        }