/// <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 #2
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);
        }
Exemple #3
0
        /// <summary>
        /// Возвращает строковое представлеине данной матрицы.
        /// </summary>
        /// <returns>Строковое представлеине данной матрицы.</returns>
        /// <remarks>
        /// <code>
        /// var matrix = new Matrix(new[] {new Vector(1, 2, 3), new Vector(3, 4)});
        /// Console.Write(matrix); //Результат: l̄₁ = x̄₁ + 2 x̄₂ + 3 x̄₃ l̄₂ = 3 x̄₁ + 4 x̄₂
        /// </code>
        /// </remarks>
        public override string ToString()
        {
            var result = "";

            var isEmpty = true;

            //Знак вектора
            var line = "l" + CStatic.Macron;

            for (var i = 0; i < Length; i++)
            {
                if (i > 0)
                {
                    result += CStatic.EmSp;
                }

                var vector = this[i];
                isEmpty &= vector == Vector.Empty;
                result  += line + CStatic.GetIndex(i + 1) + " = " + vector;
            }

            return(isEmpty ? "Ø" : result);
        }