Package ptolemy.math

Examples of ptolemy.math.Complex

@author Edward A. Lee, Jeff Tsay, Steve Neuendorffer, Adam Cataldo @version $Id: Complex.java,v 1.91 2007/12/06 21:57:08 cxh Exp $ @since Ptolemy II 0.2 @Pt.ProposedRating Yellow (eal) @Pt.AcceptedRating Red (cxh)

                jjtc001 = false;
                try {
                    x = token.image.toLowerCase();
                    len = x.length();
                    Double imag = new Double(x.substring(0, len - 1));
                    Complex value = new Complex(0, imag.doubleValue());
                    jjtn001._ptToken = new ComplexToken(value);
                    jjtn001._isConstant = true;
                } catch (NumberFormatException ee) {
                    {
                        if (true) {
                            throw new ParseException("Unable to convert token "
                                    + token.image + " to a complex number.");
                        }
                    }
                }
            } finally {
                if (jjtc001) {
                    jjtree.closeNodeScope(jjtn001, true);
                }
            }
            break;
        case DOUBLE:
            ASTPtLeafNode jjtn002 = new ASTPtLeafNode(JJTPTLEAFNODE);
            boolean jjtc002 = true;
            jjtree.openNodeScope(jjtn002);
            try {
                jj_consume_token(DOUBLE);
                jjtree.closeNodeScope(jjtn002, true);
                jjtc002 = false;
                try {
                    x = token.image.toLowerCase();
                    len = x.length();
                    if (x.endsWith("f")) {
                        Float value = new Float(x.substring(0, len - 1));
                        jjtn002._ptToken = new FloatToken(value.floatValue());
                    } else if (x.endsWith("d") || x.endsWith("p")) {
                        // all floating point numbers are double
                        Double value = new Double(x.substring(0, len - 1));
                        if (x.endsWith("p")) {
                            jjtn002._ptToken = new PetiteToken(value
                                    .doubleValue());
                        } else {
                            jjtn002._ptToken = new DoubleToken(value
                                    .doubleValue());
                        }
                    } else {
                        Double value = new Double(x);
                        jjtn002._ptToken = new DoubleToken(value.doubleValue());
                    }
                    jjtn002._isConstant = true;
                } catch (NumberFormatException ee) {
                    {
                        if (true) {
View Full Code Here


     @param x The first complex number.
     *  @param y The second complex number.
     *  @return The distance.
     */
    private double _computeEuclideanDistance(Complex x, Complex y) {
        Complex z = x.subtract(y);
        return z.magnitude();
    }
View Full Code Here

     *  of the Complex is the value of this token, the imaginary part
     *  is set to 0.
     @return A Complex.
     */
    public Complex complexValue() {
        return new Complex(_value);
    }
View Full Code Here

     *  of the Complex is the value of this token, the imaginary part
     *  is set to 0.
     @return A Complex.
     */
    public Complex complexValue() {
        return new Complex(unsignedConvert(_value));
    }
View Full Code Here

    /** Return a hash code value for this token. This method returns the
     *  integer portion of the magnitude of the sum of the elements.
     *  @return A hash code value for this token.
     */
    public int hashCode() {
        Complex sum = new Complex(0);

        for (int i = 0; i < _rowCount; i++) {
            for (int j = 0; j < _columnCount; j++) {
                sum = sum.add(_value[i][j]);
            }
        }

        return (int) sum.magnitude();
    }
View Full Code Here

     *  supported by the derived class.
     *  @return A new ComplexMatrixToken containing the result.
     */
    protected MatrixToken _addElement(Token rightArgument)
            throws IllegalActionException {
        Complex scalar;
        if (rightArgument instanceof ComplexMatrixToken) {
            if (((ComplexMatrixToken) rightArgument).getRowCount() != 1
                    || ((ComplexMatrixToken) rightArgument).getColumnCount() != 1) {
                // Throw an exception.
                return super._moduloElement(rightArgument);
View Full Code Here

     *  supported by the derived class.
     *  @return A new Token containing the result.
     */
    protected MatrixToken _divideElement(Token rightArgument)
            throws IllegalActionException {
        Complex scalar;
        if (rightArgument instanceof ComplexMatrixToken) {
            if (((ComplexMatrixToken) rightArgument).getRowCount() != 1
                    || ((ComplexMatrixToken) rightArgument).getColumnCount() != 1) {
                // Throw an exception.
                return super._moduloElement(rightArgument);
View Full Code Here

     *   supported by the derived class.
     *  @return A new ComplexMatrixToken containing the result.
     */
    protected MatrixToken _multiplyElement(Token rightArgument)
            throws IllegalActionException {
        Complex scalar;
        if (rightArgument instanceof ComplexMatrixToken) {
            if (((ComplexMatrixToken) rightArgument).getRowCount() != 1
                    || ((ComplexMatrixToken) rightArgument).getColumnCount() != 1) {
                // Throw an exception.
                return super._moduloElement(rightArgument);
View Full Code Here

     *  supported by the derived class.
     *  @return A new Token containing the result.
     */
    protected MatrixToken _subtractElement(Token rightArgument)
            throws IllegalActionException {
        Complex scalar;
        if (rightArgument instanceof ComplexMatrixToken) {
            if (((ComplexMatrixToken) rightArgument).getRowCount() != 1
                    || ((ComplexMatrixToken) rightArgument).getColumnCount() != 1) {
                // Throw an exception.
                return super._moduloElement(rightArgument);
            }
            scalar = ((ComplexMatrixToken) rightArgument).getElementAt(0, 0);
        } else {
            scalar = ((ComplexToken) rightArgument).complexValue();
        }
        Complex[][] result = ComplexMatrixMath.add(_value, scalar.negate());
        return new ComplexMatrixToken(result);
    }
View Full Code Here

     *  supported by the derived class.
     *  @return A new Token containing the result.
     */
    protected MatrixToken _subtractElementReverse(Token rightArgument)
            throws IllegalActionException {
        Complex scalar;
        if (rightArgument instanceof ComplexMatrixToken) {
            if (((ComplexMatrixToken) rightArgument).getRowCount() != 1
                    || ((ComplexMatrixToken) rightArgument).getColumnCount() != 1) {
                // Throw an exception.
                return super._moduloElement(rightArgument);
            }
            scalar = ((ComplexMatrixToken) rightArgument).getElementAt(0, 0);
        } else {
            scalar = ((ComplexToken) rightArgument).complexValue();
        }
        Complex[][] result = ComplexMatrixMath.negative(ComplexMatrixMath.add(
                _value, scalar.negate()));
        return new ComplexMatrixToken(result);
    }
View Full Code Here

TOP

Related Classes of ptolemy.math.Complex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.