Exemple #1
0
        /// <summary>
        /// Cross product for 3 components vector.
        /// </summary>
        /// <param name="v1"></param>
        /// <param name="v2"></param>
        /// <returns></returns>
        public QsVector VectorProduct(QsVector v2)
        {
            if (this.Count != v2.Count)
            {
                throw new QsException("Vectors are not equal");
            }
            if (this.Count != 3)
            {
                throw new QsException("Cross product only happens with 3 component vector");
            }

            // cross product as determinant of matrix.

            QsMatrix mat = new QsMatrix(
                new QsVector(QsScalar.One, QsScalar.One, QsScalar.One)
                , this
                , v2);

            return(mat.Determinant());

            // problem now: what if we have more than 3 elements in the vector.
            // there is no cross product for more than 3 elements for vectors.
        }
        public override QsValue Execute(Token expression)
        {
            string operation = expression.TokenValue;

            if (operation.Equals("Transpose()", StringComparison.OrdinalIgnoreCase))
            {
                return(this.Transpose());
            }

            if (operation.Equals("Identity", StringComparison.OrdinalIgnoreCase))
            {
                return(this.Identity);
            }

            if (operation.Equals("Determinant", StringComparison.OrdinalIgnoreCase))
            {
                return(QsMatrix.Determinant(this));
            }

            if (operation.Equals("Cofactors", StringComparison.OrdinalIgnoreCase))
            {
                return(this.Cofactors);
            }

            if (operation.Equals("Adjoint", StringComparison.OrdinalIgnoreCase))
            {
                return(this.Adjoint);
            }

            if (operation.Equals("Inverse", StringComparison.OrdinalIgnoreCase))
            {
                return(this.Inverse);
            }


            throw new QsException("Not implemented or Unknow method for the matrix type");
        }