コード例 #1
0
        /// <summary>
        /// returns the eigen values and eigen vectors of a matrix
        /// IMPORTANT: THIS METHOD NEEDS DEBUGGING.
        /// IT RETURNS THE NEGATIVE VALUES OF THE EIGEN VECTORS ON A TOY EXMAPLE
        ///                 double[,] matrix = {
        ///                                { 3.0, -1.0 },
        ///                                { -1.0, 3.0 }
        ///                            };
        /// eigen values are correct ie, 2.0, 4.0; but in the wrong order.
        /// </summary>
        public static Tuple <double[], double[, ]> EigenVectors(double[,] matrix)
        {
            Evd <double> eigen = DenseMatrix.OfArray(matrix).Evd();
            Vector <System.Numerics.Complex> eigenvaluesComplex = eigen.EigenValues;

            //WriteArrayOfComplexNumbers(eigenvalues);

            double[] eigenvaluesReal = new double[eigenvaluesComplex.Count];
            for (int i = 0; i < eigenvaluesComplex.Count; i++)
            {
                System.Numerics.Complex c = eigenvaluesComplex[i];
                double magnitude          = c.Magnitude;
                Console.WriteLine("eigen value[{0}]     {1}     Magnitude={2}", i, c.ToString(), magnitude);
            }

            Matrix <double> eigenvectorsComplex = eigen.EigenVectors;

            double[,] eigenvectorsReal = new double[eigenvaluesComplex.Count, matrix.GetLength(0)];
            for (int col = 0; col < eigenvectorsComplex.RowCount; col++)
            {
                Vector <double> ev = eigenvectorsComplex.Column(col);
                for (int i = 0; i < ev.Count; i++)
                {
                    eigenvectorsReal[col, i] = ev[i];
                    Console.WriteLine("eigen vector {0}, value {1} = {2}", col, i, ev[i]);
                }
            }

            return(Tuple.Create(eigenvaluesReal, eigenvectorsReal));
        }
コード例 #2
0
        public QA GetImaginaryDivideQA()
        {
            System.Numerics.Complex z1 = new System.Numerics.Complex(ran.Next(1, 5), ran.Next(1, 5)), z2 = new System.Numerics.Complex(ran.Next(1, 5), ran.Next(1, 5));
            QA result;

            result.Q = z1.ToString() + "/" + z2.ToString();
            result.A = (z1 / z2).ToString();
            return(result);
        }
コード例 #3
0
        public static string ToMathString(this System.Numerics.Complex z)
        {
            //if (double.IsNaN(z.Real) && double.IsNaN(z.Imaginary))
            //return "NaN";

            switch (Properties.Settings.Default.NumericalOutputNotation)
            {
            case Computator.NET.DataTypes.SettingsTypes.NumericalOutputNotationType.MathematicalNotation:
                if (z.Real == 0)
                {
                    if (z.Imaginary == 1.0)
                    {
                        return("i");
                    }

                    if (z.Imaginary == -1.0)
                    {
                        return("-i");
                    }

                    return(z.Imaginary != 0
                            ? string.Format("{0}{1}i", z.Imaginary.ToMathString(), Computator.NET.DataTypes.Text.SpecialSymbols.DotSymbol)
                            : "0");
                }

                if (z.Imaginary == 0)
                {
                    return(z.Real.ToMathString());
                }
                return((z.Imaginary > 0 || double.IsNaN(z.Imaginary))
                        ? string.Format("{0}+{1}{2}i", z.Real.ToMathString(), z.Imaginary.ToMathString(),
                                        Computator.NET.DataTypes.Text.SpecialSymbols.DotSymbol)
                        : string.Format("{0}{1}{2}i", z.Real.ToMathString(), z.Imaginary.ToMathString(),
                                        Computator.NET.DataTypes.Text.SpecialSymbols.DotSymbol));

            default:
                //case NumericalOutputNotationType.EngineeringNotation:
                return(z.ToString(System.Globalization.CultureInfo.InvariantCulture));
            }
        }