/// <summary>
        /// Возвращает строковое представлеине данного кватерниона.
        /// </summary>
        /// <returns>Строковое представлеине данного кватерниона.</returns>
        /// <remarks>
        /// <code>
        /// var q = Quaternion.GetRotation(Math.PI, new Point3D(1, 1, 1));
        /// Console.Write(q); //Результат: √3/3 i + √3/3 j + √3/3 k
        /// </code>
        /// </remarks>
        public override string ToString()
        {
            if (0D.Equals(W) && 0D.Equals(U.X) && 0D.Equals(U.Y) && 0D.Equals(U.Z))
            {
                return("0");
            }

            if (double.IsNaN(W) || double.IsNaN(U.X) || double.IsNaN(U.Y) || double.IsNaN(U.Z))
            {
                return("NaN");
            }

            var result = "";


            var order = Max(0, 13 - (int)GetOrder(Abs));

            CStatic.AddLinearItem(ref result, System.Math.Round(W, order), null);
            CStatic.AddLinearItem(ref result, System.Math.Round(U.X, order), "i");
            CStatic.AddLinearItem(ref result, System.Math.Round(U.Y, order), "j");
            CStatic.AddLinearItem(ref result, System.Math.Round(U.Z, order), "k");

            /*
             * var order = 1E13*Abs;
             * CStatic.AddLinearItem(ref result, Round15(W, order), null);
             * CStatic.AddLinearItem(ref result, Round15(U.X, order), "i");
             * CStatic.AddLinearItem(ref result, Round15(U.Y, order), "j");
             * CStatic.AddLinearItem(ref result, Round15(U.Z, order), "k");
             */


            return(result);
        }
        /// <summary>
        /// Возвращает строковое представлеине исходного многочлена Лежандра.
        /// </summary>
        /// <returns>Строковое представлеине исходного многочлена Лежандра.</returns>
        /// <remarks>
        /// <code>
        /// var pol = new LegendrePolynomial(6);
        /// Console.Write(pol); //Результат: -5/16 + 105/16 x² - 315/16 x⁴ + 231/16 x⁶, alternative: (231 x⁶ - 315 x⁴ + 105 x² - 5) / 16
        /// </code>
        /// </remarks>
        public override string ToString()
        {
            var result = "";

            int den;

            switch (Deg)
            {
            default:
                den = 1;
                break;

            case 2:
            case 3:
                den = 2;
                break;

            case 4:
            case 5:
                den = 8;
                break;

            case 6:
            case 7:
                den = 16;
                break;

            case 8:
            case 9:
                den = 128;
                break;

            case 10:
                den = 256;
                break;
            }

            for (var i = A.Length - 1; i >= 0; i--)
            {
                var val = i == 0 ? "" : "x";
                if (i > 1)
                {
                    val += CStatic.GetIndex(i, true);
                }

                CStatic.AddLinearItem(ref result, A[i] * den, val);
            }

            if (den > 1)
            {
                result = "(" + result + ") / " + den;
            }

            return(base.ToString() + ", alternative: " + result);
        }
Exemple #3
0
        /// <summary>
        /// Возвращает строковое представлеине данного комплексного числа.
        /// </summary>
        /// <returns>Строковое представление данного комплексного числа.</returns>
        /// <remarks>
        /// <code>
        /// var num = new Complex(2, -1);
        /// Console.Write(num); //Результат: 2 - i
        /// Console.Write(-2*num); //Результат: -4 + 2i
        /// </code>
        /// </remarks>
        public override string ToString()
        {
            if (0D.Equals(R) && 0D.Equals(I))
            {
                return("0");
            }

            if (double.IsNaN(R) || double.IsNaN(I))
            {
                return("NaN");
            }

            var result = "";

            CStatic.AddLinearItem(ref result, R, null);
            CStatic.AddLinearItem(ref result, I, "i");
            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Возвращает строковое представлеине данного линейного уравнения.
        /// </summary>
        /// <returns>Строковое представление данного линейного уравнения.</returns>
        /// <remarks>
        /// <code>
        /// var linear = new Linear(new double[] {3, 1, -1}, -4);
        /// Console.Write(linear); //Результат: 3 x₁ + x₂ - x₃ = -4
        /// Console.Write(-linear/3); //Результат: -x₁ - 1/3 x₂ + 1/3 x₃ = 4/3
        /// </code>
        /// </remarks>
        public override string ToString()
        {
            var result = CStatic.GetToStringHashValue(this);

            if (result != null)
            {
                return(result);
            }
            result = "";


            for (var i = 0; i < A.Length; i++)
            {
                var sym = "x" + CStatic.GetIndex(i + 1);
                CStatic.AddLinearItem(ref result, A[i], sym);
            }
            result  = result == "" ? "0" : result;
            result += " = " + CStatic.DoubleToString(Y);


            CStatic.AddToStringHashValue(this, result);
            return(result);
        }