Package jscicalc.complex

Examples of jscicalc.complex.Complex


     * Set substitution to variable = x
     * @param x The value to be substituted
     * @return A substitued object
     */
    protected OObject substitute( double x ){
  substitution.add( variable, new Complex( x ) );
  OObject result = oobject.substitute( substitution ).auto_simplify();
//   System.out.print( "Locus.substitute(): " );
//   final int maxLength = 120;
//   final int sigDigits = 32;
//   jscicalc.Base base = jscicalc.Base.DECIMAL;
View Full Code Here


  System.out.print( "[function( " );
  System.out.print( t.toModelX( x ) );
  System.out.print( " ) = " );
  OObject p = substitute( t.toModelX( x ) );
  if( p instanceof Complex ){
      Complex z = (Complex)p;
      if( Math.abs( z.imaginary() ) < epsilon ){
    double y = z.real();
    System.out.print( y );
    System.out.print( "]" );
    return t.toViewY( z.real() );
      }
  }
  return Double.NaN;
    }
View Full Code Here

     */
    public Product( Expression expression, final boolean inverse ){
  if( expression instanceof Product ){
      Product product = (Product)expression;
      if( inverse ){
    complex = new Complex( 1 );
    complex = complex.divide( product.complex );
    expressionList = product.divisorList;
    divisorList = product.expressionList;
      } else {
    complex = product.complex;
    expressionList = product.expressionList;
    divisorList = product.divisorList;
      }
  } else {
      complex = new Complex( 1 ); //one
      if( inverse ){
    expressionList = new java.util.LinkedList<Expression>();
    divisorList = new java.util.LinkedList<Expression>();
    divisorList.add( expression );
      } else {
View Full Code Here

     * @param b The Base
     * @return The number as a double
     * @see Parser
     */
    public static Complex parseString( String s, Base b ){
  return new Complex( dparseString( s, b ) );
    }
View Full Code Here

    /**
     * Construct a Product.
     */
    public Product(){
  complex = new Complex(); //zero
  expressionList = new java.util.LinkedList<Expression>();
  divisorList = new java.util.LinkedList<Expression>();
    }
View Full Code Here

     * Create a copy of this Product.
     * @return a copy of this
     */
    public Product clone(){
  Product copy = new Product();
  copy.complex = new Complex( complex.real(), complex.imaginary() );
  copy.expressionList = new java.util.LinkedList<Expression>();
  for( java.util.ListIterator<Expression>
     i = getExpressionList().listIterator(); i.hasNext(); ){
      copy.expressionList.add( i.next() );
  }
View Full Code Here

     * for a single object.
     * @return simplified expression
     */
    public OObject unBox(){
  if( divisorList.isEmpty() && expressionList.size() == 1 &&
      complex.subtract( new Complex( 1 ) ).isZero() ){
      return expressionList.getFirst();
  } else if( divisorList.isEmpty() && expressionList.isEmpty() ){
      return complex;
  } else {
      return this;
View Full Code Here

     * non-integer powers.
     * @param n The integer (actually a long)
     * @return An integer power
     */
    OObject integer_power( long n ){
  Complex z = new Complex( n );
  Product result = new Product();
  result.complex = complex.pow( z );
  for( java.util.ListIterator<Expression> i = expressionList.listIterator();
       i.hasNext(); ){
      Expression e = i.next();
View Full Code Here

    public OObject auto_simplify(){
  // first remove quotients
  for( java.util.ListIterator<Expression> i = divisorList.listIterator();
       i.hasNext(); ){
      Expression e = i.next();
      OObject o = new Power( e, new Complex( -1 ) ).auto_simplify();
      if( o instanceof Complex ){
    complex = complex.divide( (Complex)o );
      } else if( o instanceof Expression ){
    expressionList.add( (Expression)o );
      } else {
    return new jscicalc.Error( "Product.auto_simplify() error" );
      }
  }
  divisorList.clear();
  // simplify remaining expressions
  for( java.util.ListIterator<Expression> i = expressionList.listIterator();
       i.hasNext(); ){
      OObject o = i.next().auto_simplify();
      if( o instanceof Complex ){
    complex = complex.multiply( (Complex)o );
    i.remove();
      } else if( o instanceof Expression ){
    i.set( (Expression)o );
      } else {
    return new jscicalc.Error( "Product.auto_simplify() error" );
      }
  }
  sort();
  if( expressionList.isEmpty() ) return unBox(); // should be a Complex
  // now work through expressions in product
  java.util.ListIterator<Expression> i = expressionList.listIterator();
  Expression f = null; // initialise for loop
  for( Expression e = i.next(); i.hasNext(); e = f ){
      OObject base_e = e;
      OObject exponent_e = new Complex( 1 );
      if( e instanceof Power ){
    base_e = ((Power)e).base();
    exponent_e = ((Power)e).exponent();
      }
      f = i.next();
      OObject base_f = f;
      OObject exponent_f = new Complex( 1 );
      if( f instanceof Power ){
    base_f = ((Power)f).base();
    exponent_f = ((Power)f).exponent();
      }
      if( base_e.compareTo( base_f ) == 0 ){
View Full Code Here

  if( expression instanceof Sum ){
      Sum sum = (Sum)expression;
      complex = sum.complex;
      expressionList = sum.expressionList;
  }
  complex = new Complex(); //zero
  expressionList = new java.util.LinkedList<Expression>();
  expressionList.add( expression );
    }
View Full Code Here

TOP

Related Classes of jscicalc.complex.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.