org.statcato.calculator
Class MathOperations

java.lang.Object
  extended by org.statcato.calculator.MathOperations

public class MathOperations
extends java.lang.Object

Mathematical operations used in the calculator application.

Since:
1.0
Version:
%I%, %G%
Author:
Margaret Yau

Constructor Summary
MathOperations()
           
 
Method Summary
static CompUnit add(CompUnit c1, CompUnit c2)
          Adds two computational units.
static java.util.Vector<java.lang.Double> add(java.util.Vector<java.lang.Double> v1, java.util.Vector<java.lang.Double> v2)
          Adds the numbers in the two given vectors in a pairwise fashion.
static CompUnit divide(CompUnit c1, CompUnit c2)
          Divides two computational units.
static double factorial(double x)
          Returns the factorial of x.
static CompUnit functionCall(CompUnit c, MathFunction f)
           
static CompUnit multiply(CompUnit c1, CompUnit c2)
          Multiplies two computational units.
static java.util.Vector<java.lang.Double> multiply(java.util.Vector<java.lang.Double> v1, java.util.Vector<java.lang.Double> v2)
          Multiplies the numbers in the two given vectors in a pairwise fashion.
static CompUnit negate(CompUnit c)
          Returns the negation of a computation unit.
static CompUnit power(CompUnit c1, CompUnit c2)
          Returns the value of the first computation unit raised to the second computational unit.
static java.util.Vector<java.lang.Double> power(java.util.Vector<java.lang.Double> v1, java.util.Vector<java.lang.Double> v2)
          For each pair of numbers in the corresponding positions in the two vectors, raises the first number to the power specified by the second number.
static CompUnit reciprocal(CompUnit c)
          Returns the reciprocal of a computational unit.
static CompUnit subtract(CompUnit c1, CompUnit c2)
          Returns the difference between two computational units.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MathOperations

public MathOperations()
Method Detail

add

public static java.util.Vector<java.lang.Double> add(java.util.Vector<java.lang.Double> v1,
                                                     java.util.Vector<java.lang.Double> v2)
Adds the numbers in the two given vectors in a pairwise fashion. The sum of a pair containing a missing number is simply the nonmissing number.

Parameters:
v1 - vector 1
v2 - vector 2
Returns:
vector containing pairwise sums

add

public static CompUnit add(CompUnit c1,
                           CompUnit c2)
Adds two computational units. If the two units are numbers, simply adds them. If the two units are columns, adds each pair of numbers in the corresponding positions in the columns. If one unit is number and the other is a column, add the number to each of the numbers in the column.

Parameters:
c1 - CompUnit 1
c2 - CompUnit 2
Returns:
a CompUnit containing the sum of the two inputs

negate

public static CompUnit negate(CompUnit c)
Returns the negation of a computation unit. If the unit is a number, simply negates it. If the unit is a column, negates each number in the column.

Parameters:
c - computation unit
Returns:
a CompUnit containing the negation of the argument

multiply

public static java.util.Vector<java.lang.Double> multiply(java.util.Vector<java.lang.Double> v1,
                                                          java.util.Vector<java.lang.Double> v2)
Multiplies the numbers in the two given vectors in a pairwise fashion. The product of a pair containing a missing number is null.

Parameters:
v1 - vector 1
v2 - vector 2
Returns:
vector containing pairwise products

subtract

public static CompUnit subtract(CompUnit c1,
                                CompUnit c2)
Returns the difference between two computational units. If the two units are numbers, simply subtracts the two. If the two units are columns, finds the difference of each pair of numbers in the corresponding positions in the columns. If the first unit is a number and the second is a column, adds the number to the negation of each number in the column. If the first is a column and the second is a number, adds the negation of the number to each number in the column.

Parameters:
c1 - CompUnit 1
c2 - CompUnit 2
Returns:
a CompUnit containing the difference of the two inputs

multiply

public static CompUnit multiply(CompUnit c1,
                                CompUnit c2)
Multiplies two computational units. If the two units are numbers, simply multiplies them. If the two units are columns, multiplies each pair of numbers in the corresponding positions in the columns. If one unit is number and the other is a column, multiplies the number to each of the numbers in the column.

Parameters:
c1 - CompUnit 1
c2 - CompUnit 2
Returns:
a CompUnit containing the product of the two inputs

reciprocal

public static CompUnit reciprocal(CompUnit c)
Returns the reciprocal of a computational unit.

Parameters:
c - computational unit
Returns:
reciprocal of the given computational unit.

divide

public static CompUnit divide(CompUnit c1,
                              CompUnit c2)
Divides two computational units. If the two units are numbers, simply divides them. If the two units are columns, divides each pair of numbers in the corresponding positions in the columns. If the first is a number and the second is a column, multiplies the number with the reciprocal of each number in the column. If the first is a column and the second is a number, mutiplies the reciprocal of the number with each number in the column.

Parameters:
c1 - CompUnit 1
c2 - CompUnit 2
Returns:
a CompUnit containing the product of the two inputs

power

public static CompUnit power(CompUnit c1,
                             CompUnit c2)
Returns the value of the first computation unit raised to the second computational unit. If the two units are columns, performs the computation pairwise. If one of the arguments is a number, uses the number to fill a column and performs the computation with the other argument pairwise.

Parameters:
c1 - CompUnit 1
c2 - CompUnit 2
Returns:
a CompUnit containing the value of the first unit raised to the power of the second unit

power

public static java.util.Vector<java.lang.Double> power(java.util.Vector<java.lang.Double> v1,
                                                       java.util.Vector<java.lang.Double> v2)
For each pair of numbers in the corresponding positions in the two vectors, raises the first number to the power specified by the second number. The result is null if the pair contains a missing number.

Parameters:
v1 - vector 1
v2 - vector 2
Returns:
vector containing pairwise products

functionCall

public static CompUnit functionCall(CompUnit c,
                                    MathFunction f)

factorial

public static double factorial(double x)
Returns the factorial of x. Assumes that x is a nonnegative integer.

Parameters:
x - nonnegative integer
Returns:
factorial of x