JavaView® v2.12

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.

The following constant(s) are implemented by default: {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', ...

An arbitrary number of additional variables can be added to a function.

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

Usage:

     // Graph of real-valued function in one variable
     PuFunction function = new PuFunction(1, 1);
 
     m_function.setName("Sin Function");
     m_function.setExpression("sin(u)", 0);
     double result = m_function.eval(double arg);
 
or
     // Parametrized surface from R2 to R3
     PuFunction function = new PuFunction(2, 3);
 
     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);
 
Later, a function can be evaluated by calling
     m_function.eval(double [] result, double [] arg);
 

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

Version:
05.05.01, 2.20 revised (kp) Method findZero and findValue moved to jvx.numeric.PnRootFinder.
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

Fields inherited from class jv.object.PsObject
HAS_CONFIG_PANEL, HAS_INFO_PANEL, HAS_MATERIAL_PANEL, HAS_TEXTURE_PANEL, INSPECTOR_INFO, INSPECTOR_INFO_EXT, IS_DELETED, IS_FIXED, IS_SELECTED, IS_USED, 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)
          Deprecated. use jvx.numeric.PnRootFinder#findValue instead, this method is no longer functional.
 double[] findZero(double[] a, double[] b)
          Deprecated. use jvx.numeric.PnRootFinder#findZero instead, this method is no longer functional.
 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.
 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, assureInspector, 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, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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.

If there exist no default function, then the first invocation of this method with a non-empty expression argument is assigned as default expression.


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)
Deprecated. use jvx.numeric.PnRootFinder#findZero instead, this method is no longer functional.

Finds the zero position on a straight line segment between two vertices using a bisection algorithm. The function must be defined on the full straight line segment.

This method 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)
Deprecated. use jvx.numeric.PnRootFinder#findValue instead, this method is no longer functional.

Finds the position of a value on a straight line segment between two vertices using a bisection algorithm. The function must be defined on the full straight line segment.

First the function is evaluated at the two end points. If either of them is already equal to the value, then this vertex is returned. If both values are bigger or smaller, then a warning message is issued and the first vertex is returned.

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

Parameters:
a - coordinates of the first vertex
b - coordinates of the second vertex
value - function value to search for its argument vertex
Returns:
vertex in the given interval whose function value is equal to the given value.

JavaView® v2.12

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