JavaView® v2.00.008

jv.function
Class PuFunction

java.lang.Object
  |
  +--jv.object.PsObject
        |
        +--jv.function.PuFunction
All Implemented Interfaces:
java.lang.Cloneable, PsUpdateIf, java.io.Serializable

public class PuFunction
extends PsObject

Describes a function in terms of a string with variables and constants. Strings may be interactively edited, for example, when studying parametrized surfaces.

A number of constants are implemented, like 'pi'. The first independent variables have names 'u', 'v', 'w' in this order. If more than three variables are use, they are numbered as 'u0', 'u1', ...

Additional variables may be added to function.

Info panel of the function object may be added to some panel to allow interactive editing of the functions.

Usage:

     m_function.setName("Kuen Surface");
     m_function.setExpression("2./(1.+(u*sin(v))^2)*sqrt(1.+u*u)*sin(v)*cos(u-atan(u))", 0);
     m_function.setExpression("2./(1.+(u*sin(v))^2)*sqrt(1.+u*u)*sin(v)*sin(u-atan(u))", 1);
     m_function.setExpression("log(tan(v/2.))+2./(1.+(u*sin(v))^2)*cos(v)", 2);
     m_function.eval(double [] result, double [] arg);
 or
     m_function.setName("Real-valued function of one variable");
     m_function.setExpression("sin(u)", 0);
     double result = m_function.eval(double arg);
 
Later the function may be evaluated by
     m_function.eval(double [] result, double [] arg);
 

See jv.thirdParty.expr.Expr for a list and notation of functions.

Version:
02.10.99, 2.10 revised (kp) Additional eval() added for functions f:R->R.
04.07.99, 2.01 revised (kp) Eval() instead of fun() for function evaluation.
00.00.98, 1.00 created (kp) First skeleton
Author:
Konrad Polthier
See Also:
Expr, Serialized Form

Field Summary
protected  java.lang.String[] m_defExprString
           
protected  Expr[] m_expr
           
protected  java.lang.String[] m_exprString
           
protected  int m_numFunctions
           
protected  int m_numParameters
           
protected  int m_numVariables
           
protected  java.util.Hashtable m_parm
           
protected  Variable[] m_var
           
 
Fields inherited from class jv.object.PsObject
HAS_CONFIG_PANEL, HAS_INFO_PANEL, HAS_MATERIAL_PANEL, INSPECTOR_INFO, INSPECTOR_INFO_EXT, IS_DELETED, IS_FIXED, IS_SELECTED, IS_USED, m_infoPanel, m_name, m_panelList, m_parent, m_tag, m_updateList, NUM_TAGS
 
Constructor Summary
PuFunction()
           
PuFunction(int numVariables, int numFunctions)
           
 
Method Summary
 void addParameter(java.lang.String name, double initialValue)
          Add additional variables to all expressions, usually used as constants or parameters.
 double eval(double arg)
          Evaluate a real-valued function of one variable.
 boolean eval(double[] result, double[] arg)
          Evaluate an m-dim functions of n-variables'.
 double eval(int ind, double[] arg)
          Evaluate a component of an m-dim functions of n-variables'.
 double[] findValue(double[] a, double[] b, double value)
          Finds the position of a value between two vertices.
 double[] findZero(double[] a, double[] b)
          Finds the zero position between two vertices.
 java.lang.String getExpression(int ind)
          Get string of function with index ind.
 int getNumFunctions()
          Get number of functions.
 int getNumVariables()
          Get number of arguments used in current functions.
 void init()
          If instance has missing name then assign default name 'object_NUMBER' where number is the total number of already created instances.
 boolean setExpression(java.lang.String[] s)
          Supply string array of functions.
 boolean setExpression(java.lang.String s, int ind)
          Set string of function with index ind, overwrite default values.
protected  boolean setExpressionFromPanel(java.lang.String s, int ind)
          Set string of function with index ind from panel, i.e. do not overwrite default.
 void setNumFunctions(int numFunctions)
          Set number of functions.
 void setNumVariables(int numVariables)
          Set number of arguments used in current functions.
 void setParameter(java.lang.String name, double value)
          Set value of variable in all expressions, usually used as constants or parameters.
 
Methods inherited from class jv.object.PsObject
addInspector, addUpdateListener, clearTag, clone, clone, clone, copy, getFather, getInfoPanel, getInspector, getName, getNumObjects, hasInspector, hasTag, hasUpdateListener, instanceOf, instanceOf, removeInspector, removeUpdateListener, setName, setParent, setTag, toString, update, updatePanels
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_numVariables

protected int m_numVariables

m_numFunctions

protected int m_numFunctions

m_numParameters

protected int m_numParameters

m_expr

protected Expr[] m_expr

m_exprString

protected java.lang.String[] m_exprString

m_defExprString

protected java.lang.String[] m_defExprString

m_var

protected Variable[] m_var

m_parm

protected java.util.Hashtable m_parm
Constructor Detail

PuFunction

public PuFunction()

PuFunction

public PuFunction(int numVariables,
                  int numFunctions)
Method Detail

init

public void init()
Description copied from class: PsObject
If instance has missing name then assign default name 'object_NUMBER' where number is the total number of already created instances.
Overrides:
init in class PsObject

addParameter

public void addParameter(java.lang.String name,
                         double initialValue)
Add additional variables to all expressions, usually used as constants or parameters.

setParameter

public void setParameter(java.lang.String name,
                         double value)
Set value of variable in all expressions, usually used as constants or parameters.

getNumVariables

public int getNumVariables()
Get number of arguments used in current functions.

setNumVariables

public void setNumVariables(int numVariables)
Set number of arguments used in current functions.

getNumFunctions

public int getNumFunctions()
Get number of functions.

setNumFunctions

public void setNumFunctions(int numFunctions)
Set number of functions.

getExpression

public java.lang.String getExpression(int ind)
Get string of function with index ind.

setExpression

public boolean setExpression(java.lang.String s,
                             int ind)
Set string of function with index ind, overwrite default values.

setExpressionFromPanel

protected boolean setExpressionFromPanel(java.lang.String s,
                                         int ind)
Set string of function with index ind from panel, i.e. do not overwrite default.

setExpression

public boolean setExpression(java.lang.String[] s)
Supply string array of functions.

eval

public double eval(double arg)
Evaluate a real-valued function of one variable.
Parameters:
arg - Value of function argument.
Returns:
double Function value evaluated at 'arg'.

eval

public double eval(int ind,
                   double[] arg)
Evaluate a component of an m-dim functions of n-variables'.
Parameters:
ind - Component to evaluate
arg - Array with value for each function argument.
Returns:
double value of function component evaluated at argument

eval

public boolean eval(double[] result,
                    double[] arg)
Evaluate an m-dim functions of n-variables'.
Parameters:
result - Existing array to contain the computed function values.
arg - Array with value for each function argument.
Returns:
false if an error occurred, or data is missing.

findZero

public double[] findZero(double[] a,
                         double[] b)
Finds the zero position between two vertices. Just calls findValue with value of zero.
Parameters:
a - a double[] with one vertex
b - a double[] with another vertex
Returns:
a double[] with the zero crossing point

findValue

public double[] findValue(double[] a,
                          double[] b,
                          double value)
Finds the position of a value between two vertices. That is it calculates the function values and then starts bisection of the connecting line iteratively.

First the two limiting function values are calculated. If one of them is already equal to the value it is returned. If both of them are bigger or both of them are smaller there comes a warning message and the first one is returned.

Then the bisection starts by computing the midpoint, choosing the section with different signs for the difference, bisecting this again and so on until one of the function values becomes equal. This vertex is finally returned.

Parameters:
a - a double[] with one vertex
b - a double[] with another vertex
value - a double with the function value to find
Returns:
a double[] with the point with the given function value

JavaView® v2.00.008

The software JavaView® is copyright protected. All Rights Reserved.