Exemple #1
0
        EigenvalueDecomposition(
            Matrix Arg
            )
        {
            double[][] A = Arg;
            n = Arg.ColumnCount;
            V = Matrix.CreateMatrixData(n, n);
            d = new double[n];
            e = new double[n];

            isSymmetric = true;
            for (int j = 0; (j < n) & isSymmetric; j++)
            {
                for (int i = 0; (i < n) & isSymmetric; i++)
                {
                    isSymmetric &= (A[i][j] == A[j][i]);
                }
            }

            if (isSymmetric)
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        V[i][j] = A[i][j];
                    }
                }

                SymmetricTridiagonalize();

                SymmetricDiagonalize();
            }
            else
            {
                H = new double[n][];
                for (int i = 0; i < n; i++)
                {
                    double[] Hi = new double[n];
                    double[] Ai = A[i];

                    for (int j = 0; j < n; j++)
                    {
                        Hi[j] = Ai[j];
                    }

                    H[i] = Hi;
                }

                NonsymmetricReduceToHessenberg();

                NonsymmetricReduceHessenberToRealSchur();
            }

            _eigenValuesReal = new Vector(d);
            _eigenValuesImag = new Vector(e);
            _eigenValues     = ComplexVector.Create(d, e);

            InitOnDemandComputations();
        }
Exemple #2
0
        EigenvalueDecomposition(
            double[] d,
            double[] e)
        {
            /* TODO: unit test missing for EigenvalueDecomposition constructor. */

            _n = d.Length;
            _v = Matrix.CreateMatrixData(_n, _n);

            _d = new double[_n];
            Array.Copy(d, 0, _d, 0, _n);

            _e = new double[_n];
            Array.Copy(e, 0, _e, 1, _n - 1);

            for (int i = 0; i < _n; i++)
            {
                _v[i][i] = 1;
            }

            SymmetricDiagonalize();

            _eigenValuesReal = new Vector(_d);
            _eigenValuesImag = new Vector(_e);
            _eigenValues     = ComplexVector.Create(_d, _e);

            InitOnDemandComputations();
        }
 AlmostEqual(
     ComplexVector u,
     ComplexVector v,
     double maximumRelativeError)
 {
     return(Number.AlmostEqual(u, v, maximumRelativeError));
 }
Exemple #4
0
        EigenvalueDecomposition(
            double[] d,
            double[] e
            )
        {
            // TODO: unit test missing for EigenvalueDecomposition constructor.

            n = d.Length;
            V = Matrix.CreateMatrixData(n, n);

            this.d = new double[n];
            Array.Copy(d, 0, this.d, 0, n);

            this.e = new double[n];
            Array.Copy(e, 0, this.e, 1, n - 1);

            for (int i = 0; i < n; i++)
            {
                V[i][i] = 1;
            }

            SymmetricDiagonalize();

            _eigenValuesReal = new Vector(this.d);
            _eigenValuesImag = new Vector(this.e);
            _eigenValues     = ComplexVector.Create(this.d, this.e);

            InitOnDemandComputations();
        }
Exemple #5
0
        EigenvalueDecomposition(Matrix arg)
        {
            double[][] a = arg;
            _n = arg.ColumnCount;
            _v = Matrix.CreateMatrixData(_n, _n);
            _d = new double[_n];
            _e = new double[_n];

            _isSymmetric = true;
            for (int j = 0; (j < _n) & _isSymmetric; j++)
            {
                for (int i = 0; (i < _n) & _isSymmetric; i++)
                {
                    _isSymmetric &= (a[i][j] == a[j][i]);
                }
            }

            if (_isSymmetric)
            {
                for (int i = 0; i < _n; i++)
                {
                    for (int j = 0; j < _n; j++)
                    {
                        _v[i][j] = a[i][j];
                    }
                }

                SymmetricTridiagonalize();

                SymmetricDiagonalize();
            }
            else
            {
                _h = new double[_n][];
                for (int i = 0; i < _n; i++)
                {
                    double[] hi = new double[_n];
                    double[] ai = a[i];

                    for (int j = 0; j < _n; j++)
                    {
                        hi[j] = ai[j];
                    }

                    _h[i] = hi;
                }

                NonsymmetricReduceToHessenberg();

                NonsymmetricReduceHessenberToRealSchur();
            }

            _eigenValuesReal = new Vector(_d);
            _eigenValuesImag = new Vector(_e);
            _eigenValues     = ComplexVector.Create(_d, _e);

            InitOnDemandComputations();
        }
        AlmostEquals(ComplexVector other)
        {
            if (ReferenceEquals(other, null) ||
                _length != other.Length)
            {
                return(false);
            }

            return(Number.AlmostEqualNorm(Norm1(), other.Norm1(), (this - other).Norm1()));
        }
        AlmostEquals(
            ComplexVector other,
            double maximumRelativeError)
        {
            if (ReferenceEquals(other, null) ||
                _length != other.Length)
            {
                return(false);
            }

            return(Number.AlmostEqualNorm(Norm1(), other.Norm1(), (this - other).Norm1(), maximumRelativeError));
        }
        CrossProduct(
            IVector <Complex> u,
            IVector <Complex> v)
        {
            CheckMatchingVectorDimensions(u, v);
            if (3 != u.Length)
            {
                throw new ArgumentOutOfRangeException("u", Properties.LocalStrings.ArgumentVectorThreeDimensional);
            }

            ComplexVector product = new ComplexVector(new Complex[] {
                (u[1] * v[2]) - (u[2] * v[1]),
                (u[2] * v[0]) - (u[0] * v[2]),
                (u[0] * v[1]) - (u[1] * v[0])
            });

            return(product);
        }
Exemple #9
0
        CrossProduct(
            IVector <Complex> u,
            IVector <Complex> v
            )
        {
            CheckMatchingVectorDimensions(u, v);
            if (3 != u.Length)
            {
                throw new ArgumentOutOfRangeException("u", Resources.ArgumentVectorThreeDimensional);
            }

            ComplexVector product = new ComplexVector(new Complex[] {
                u[1] * v[2] - u[2] * v[1],
                u[2] * v[0] - u[0] * v[2],
                u[0] * v[1] - u[1] * v[0]
            });

            return(product);
        }
        Equals(ComplexVector other)
        {
            if (ReferenceEquals(other, null) ||
                _length != other.Length)
            {
                return(false);
            }

            // compare all values
            Complex[] otherData = other._data;
            for (int i = 0; i < _data.Length; i++)
            {
                if (!_data[i].Equals(otherData[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
 AlmostEqual(
     ComplexVector u,
     ComplexVector v)
 {
     return(Number.AlmostEqual(u, v));
 }
        Equals(object obj)
        {
            ComplexVector v = obj as ComplexVector;

            return(ReferenceEquals(v, null) ? false : Equals(v));
        }