org.fraid.math
Class MathHelper

java.lang.Object
  extended by org.fraid.math.MathHelper

public class MathHelper
extends java.lang.Object

Different mathematical routines. All methods are static.


Field Summary
static java.util.Random random
          Systemwide random generator.
protected static int smoothing
          The parameter which determines how smooth the lagrangeHermite approximation will be arround the sampling points.
 
Constructor Summary
MathHelper()
           
 
Method Summary
static Complex[] calc(java.util.Vector aFunctions, Complex[] aArgs, double aTime)
          Calculates the system given by aFunctions at the point aArgs.
static int getSmoothing()
          Returns the smoothing value.
static double lagrangeHermite(double aPoint, double aPX, double aPY, double aSX, double aSY, double aEX, double aEY, double aNX, double aNY)
          Given four points p1,p2,p3,p4 approximates the y-value of a point which is between p2.x and p3.x.
static int log2int(int aValue)
           
static void main(java.lang.String[] args)
          Test driver for MathHelper
static int nextpow2(double aValue)
           
static int pow2length(int aValue)
           
static void printComplexArray(Complex[] aArray)
          Test function.
static Complex quad(ComplexFunction aFun, double aLLimit, double aULimit, int aPoints)
          Test function.
static void rotate3D(DoublePoint3D aInitialPoint, DoublePoint3D aTransformedPoint, DoublePoint3D aVectorToRotateAround, double aRotationAngle, double aScale)
           
static void setSmoothing(int newSmoothing)
          Sets the smoothing value.
static Complex[] sumScalVect(double aScalar1, Complex[] aVect1, double aScalar2, Complex[] aVect2)
          Performs aScalar1*aVect1 + aScalar2*aVect2
static void transform(java.util.Vector aFunctions, Complex[] aArgs, Complex[] aTransformed)
          Transform the n-dimensional point aArgs with the transformation in aFunctions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

random

public static java.util.Random random
Systemwide random generator.


smoothing

protected static int smoothing
The parameter which determines how smooth the lagrangeHermite approximation will be arround the sampling points. The bigger the value the smoother the approximation. Too big value may generate rounding errors. Shouldn't be smaller than 1; The default is 100.

Constructor Detail

MathHelper

public MathHelper()
Method Detail

getSmoothing

public static int getSmoothing()
Returns the smoothing value.

Returns:
an int value

setSmoothing

public static void setSmoothing(int newSmoothing)
                         throws MathException
Sets the smoothing value.

Parameters:
newSmoothing - an int value
Throws:
MathException - if newSmoothing < 1

lagrangeHermite

public static double lagrangeHermite(double aPoint,
                                     double aPX,
                                     double aPY,
                                     double aSX,
                                     double aSY,
                                     double aEX,
                                     double aEY,
                                     double aNX,
                                     double aNY)
Given four points p1,p2,p3,p4 approximates the y-value of a point which is between p2.x and p3.x. Uses Hermite's idea with two points and two derivatives but approximated with third degree Lagrange schema.

Parameters:
aPoint - the abscisa of the point we are trying to approximate;
aPX - the point before the first point of the interval (aSX), needed to calculate the derivative at aSX;
aSX - the first(start) point of the interval;
aEX - the second(end) point of the interval;
aNX - the point after the end of the interval (aEX), used to calculate the derivative at the end of the interval (aEX);
Returns:
the approximated value of the function at x=a_point
See Also:
DoublePoint

sumScalVect

public static Complex[] sumScalVect(double aScalar1,
                                    Complex[] aVect1,
                                    double aScalar2,
                                    Complex[] aVect2)
Performs aScalar1*aVect1 + aScalar2*aVect2

Parameters:
aScalar1 - a double value
aVect1 - a Complex[] value
aScalar2 - a double value
aVect2 - a Complex[] value
Returns:
a Complex[] value

calc

public static Complex[] calc(java.util.Vector aFunctions,
                             Complex[] aArgs,
                             double aTime)
                      throws java.lang.Exception
Calculates the system given by aFunctions at the point aArgs. Use when solving differential equations;

Parameters:
aFunctions - the system
aArgs - the point at which we need the value calculated
aTime - optional time variable
Returns:
the result
Throws:
java.lang.Exception - if an error occurs

transform

public static void transform(java.util.Vector aFunctions,
                             Complex[] aArgs,
                             Complex[] aTransformed)
                      throws java.lang.Exception
Transform the n-dimensional point aArgs with the transformation in aFunctions.

Parameters:
the - transformation given by a system of n, n-dimensional equations;
the - point we are transforming;
Throws:
java.lang.Exception - if an error occurs

rotate3D

public static void rotate3D(DoublePoint3D aInitialPoint,
                            DoublePoint3D aTransformedPoint,
                            DoublePoint3D aVectorToRotateAround,
                            double aRotationAngle,
                            double aScale)

quad

public static Complex quad(ComplexFunction aFun,
                           double aLLimit,
                           double aULimit,
                           int aPoints)
                    throws java.lang.Exception
Test function.

Parameters:
aArray - a Complex[] value
Throws:
java.lang.Exception

log2int

public static int log2int(int aValue)
                   throws ComplexFunctionException
Throws:
ComplexFunctionException

nextpow2

public static int nextpow2(double aValue)

pow2length

public static int pow2length(int aValue)

printComplexArray

public static void printComplexArray(Complex[] aArray)
Test function.

Parameters:
aArray - a Complex[] value

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Test driver for MathHelper

Parameters:
args - a String[] value
Throws:
java.lang.Exception - if an error occurs


Fraid (system and language). (C) 2003-2007 Ivaylo Iliev
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.