Class PuFunction
- java.lang.Object
-
- jv.object.PsObject
-
- jv.function.PuFunction
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, PsUpdateIf
public class PuFunction extends PsObject
Describes one or more functions in terms of an expression string with variables and constants. Strings may be interactively edited, for example, when studying parametrized surfaces.Default variable names are {"u", "v", "w"} or, if more created with more than three variables, {"u0", "u1", "u2", ...}. A good practice is to specify individual variables directly after creating a function object using
setVariables(String []).Default names of the component functions are {"x", "y", "z", "t"} or, if more created with more than four component functions, {"F[0]", "F[1]", ...}. A good practice is to specify individual expression names directly after creating a function object using
setExpressionNames(String []).The following constant(s) are registered by default: {"Pi", "pi"}.
An arbitrary number of additional parameters can be added to a function.
Usage:
// Graph of real-valued function in one variable PuFunction function = new PuFunction(1, 1); m_function.setName("Sin Function"); m_function.setVariables(new String[] {"u"}); m_function.setExpression("sin(u)"); 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.setVariables(new String[] {"u", "v"}); m_function.setExpression(0, "2./(1.+(u*sin(v))^2)*sqrt(1.+u*u)*sin(v)*cos(u-atan(u))"); m_function.setExpression(1, "2./(1.+(u*sin(v))^2)*sqrt(1.+u*u)*sin(v)*sin(u-atan(u))"); m_function.setExpression(2, "log(tan(v/2.))+2./(1.+(u*sin(v))^2)*cos(v)"); m_function.eval(double [] result, double [] arg);Later, a function can be evaluated by callingm_function.eval(double [] result, double [] arg);See
jv.thirdParty.expr.Exprfor a list and notation of functions.- See Also:
Expr, Serialized Form- Author:
- Konrad Polthier
- Version:
- 03.04.11, 3.10 revised (kp) More eval() methods of real valued functions.
31.07.04, 3.00 revised (kp) More eval() methods; parameters are now identified by symbol instead of name, see PsObject#m_symbol.
17.01.04, 2.40 revised (kp) Method toString() implemented.
04.08.03, 2.30 revised (kp) Methods clone() and copy() implemented.
05.05.01, 2.20 revised (kp) Methods findZero() and findValue() moved to jvx.numeric.PnRootFinder.
02.10.99, 2.10 revised (kp) Additional method eval() added for functions f:R->R.
04.07.99, 2.01 revised (kp) Use method eval() instead of fun() for function evaluation.
00.00.98, 1.00 created (kp) First skeleton.
-
-
Field Summary
-
Fields inherited from class jv.object.PsObject
HAS_BOUNDARY_PANEL, HAS_CONFIG_PANEL, HAS_INFO_PANEL, HAS_LABEL_PANEL, HAS_MATERIAL_PANEL, HAS_TEXTURE_PANEL, HAS_VECTOR_PANEL, INSPECTOR_INFO, INSPECTOR_INFO_EXT, IS_DELETED, IS_FIXED, IS_FOCUSSED, IS_PICKED, IS_SELECTED, IS_USED, NUM_TAGS
-
-
Constructor Summary
Constructors Constructor and Description PuFunction()PuFunction(int numVariables, int numFunctions)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description voidaddParameter(PuDouble parm)Add adjustable function parameter to all expressions.voidaddParameter(java.lang.String symbol, double initialValue)Add additional variables to all expressions, usually used as constants or parameters.java.lang.Objectclone()Duplicate a function object by recursively cloning all instance variables.voidcopy(PsObject object)Copies data from given function object.doubleeval()Evaluate a real-valued function of one variable.doubleeval(double arg)Evaluate a real-valued function of one variable.booleaneval(double[] result)Evaluate an m-dim functions of n-variables.booleaneval(double[] result, double arg)Evaluate an m-dim function of one variable.booleaneval(double[] result, double[] arg)Evaluate an m-dim functions of n-variables.doubleeval(double arg0, double arg1)Evaluate a real-valued function of three variables.doubleeval(double arg0, double arg1, double arg2)Evaluate a real-valued function of three variables.doubleeval(int ind)Evaluate a component of an m-dim functions of n-variables'.doubleeval(int ind, double arg)Evaluate a component of an m-dim functions of one variable.doubleeval(int ind, double[] arg)Evaluate a component of an m-dim functions of n-variables.java.lang.StringgetExpression()Get string of function if number of functions is 1.java.lang.StringgetExpression(int ind)Get string of function with indexind.java.lang.StringgetExpressionName()Get string of function if number of functions is 1.java.lang.StringgetExpressionName(int ind)Get string of function with indexind.java.lang.String[]getExpressionNames()Get string of function if number of functions is 1.java.lang.String[]getExpressions()Get strings of all function.intgetNumFunctions()Get number of functions.intgetNumParameters()Get number of parameters used in current functions.intgetNumVariables()Get number of argument variables used in current functions.PuDoublegetParameter(java.lang.String symbol)Return stored function parameters as PuDouble objects.java.util.EnumerationgetParameters()Return stored function parameters as PuDouble objects.java.lang.String[]getVariables()Get array of variables names.voidinit()If instance has missing name then assign default name 'Object_NUMBER' where number is the total number of already created instances.booleansetDefExpression(int ind, java.lang.String expr)Set string of function with indexind.booleansetExpression(int ind, java.lang.String expr)Set string of function with indexind.booleansetExpression(java.lang.String expr)Supply expression of function if number of functions is 1.booleansetExpression(java.lang.String[] exprArr)Deprecated.since JavaView 3.50.003, use setExpressions(String []).booleansetExpression(java.lang.String expr, int ind)Deprecated.since JavaView 3.50.002, use setExpression(int, String);voidsetExpressionName(int ind, java.lang.String name)Set name of individual function expression.voidsetExpressionName(java.lang.String name)Set name of function expression.voidsetExpressionNames(java.lang.String[] name)Set names of all function expressions.booleansetExpressions(java.lang.String[] exprArr)Supply expressions of all functions.voidsetNumFunctions(int numFunctions)Set number of functions.voidsetNumVariables(int numVariables)Set number of argument variables used in current functions.voidsetParameter(java.lang.String symbol, double value)Set value of variable in all expressions, usually used as constants or parameters.voidsetVariables(java.lang.String[] symbol)Add symbols of variables in all expressions.java.lang.StringtoString()Create a multi-line string representation with detailed information about all instance variables.booleanupdate(java.lang.Object event)Update the class whenever a child has changed.-
Methods inherited from class jv.object.PsObject
addInspector, addUpdateListener, assureInspector, clearTag, clone, clone, getFather, getInfoPanel, getInspector, getName, getNumObjects, getSymbol, hasInspector, hasTag, hasUpdateListener, instanceOf, instanceOf, newInspector, newInspector, removeInspector, removeInspector, removeUpdateListener, setName, setParent, setSymbol, setTag, updatePanels
-
-
-
-
Constructor Detail
-
PuFunction
public PuFunction()
-
PuFunction
public PuFunction(int numVariables, int numFunctions)
-
-
Method Detail
-
init
public void init()
Description copied from class:PsObjectIf instance has missing name then assign default name 'Object_NUMBER' where number is the total number of already created instances.
-
clone
public java.lang.Object clone()
Duplicate a function object by recursively cloning all instance variables.- Overrides:
clonein classPsObject- Since:
- JavaView 2.89.000
- See Also:
PsObject.copy(PsObject)- Version:
- 30.07.03, 1.00 created (kp)
-
copy
public void copy(PsObject object)
Copies data from given function object.- Overrides:
copyin classPsObject- Since:
- JavaView 2.89.000
- See Also:
PsObject.clone()- Version:
- 30.07.03, 1.00 created (kp)
-
toString
public java.lang.String toString()
Create a multi-line string representation with detailed information about all instance variables.
-
update
public boolean update(java.lang.Object event)
Update the class whenever a child has changed. Method is usually invoked from the children.- Specified by:
updatein interfacePsUpdateIf- Overrides:
updatein classPsObject- Parameters:
event- carries a lot of information- Returns:
- true if event has been handled, otherwise false
- See Also:
PsObject.setParent(PsUpdateIf),PsObject.getFather(),PsObject.addUpdateListener(PsUpdateIf)
-
addParameter
public void addParameter(PuDouble parm)
Add adjustable function parameter to all expressions. The slider is also added as variable with given symbol and initial value to all function expressions usingaddParameter(String, double).Use
getParameter(String)to return parameter objects.This function object is registered as update listener of the slider. Whenever the slider changes then this function object updates the corresponding variable value.
- Since:
- JavaView v.3.50.002
- See Also:
getParameter(String)- Version:
- 27.07.04, 1.00 created (kp) Copied from vgp.surface.common.PgSurfaceDescr.
-
getParameter
public PuDouble getParameter(java.lang.String symbol)
Return stored function parameters as PuDouble objects. UseaddParameter(PuDouble)to store function parameter.- Parameters:
symbol- symbol of previously added PuDouble, seePuDouble#getSymbol().- Since:
- JavaView v.3.50.002
- See Also:
addParameter(PuDouble)- Version:
- 27.07.04, 1.00 created (kp) Copied from vgp.surface.common.PgSurfaceDescr.
-
getParameters
public java.util.Enumeration getParameters()
Return stored function parameters as PuDouble objects. UseaddParameter(PuDouble)to store function parameter.- Since:
- JavaView v.3.50.002
- See Also:
addParameter(PuDouble)- Version:
- 27.07.04, 1.00 created (kp) Copied from vgp.surface.common.PgSurfaceDescr.
-
getNumParameters
public int getNumParameters()
Get number of parameters used in current functions.
-
addParameter
public void addParameter(java.lang.String symbol, double initialValue)Add additional variables to all expressions, usually used as constants or parameters.
-
setParameter
public void setParameter(java.lang.String symbol, double value)Set value of variable in all expressions, usually used as constants or parameters.
-
getNumVariables
public int getNumVariables()
Get number of argument variables used in current functions.
-
setNumVariables
public void setNumVariables(int numVariables)
Set number of argument variables used in current functions.
-
getVariables
public java.lang.String[] getVariables()
Get array of variables names.
-
setVariables
public void setVariables(java.lang.String[] symbol)
Add symbols of variables in all expressions. Number of given symbols must match then number of variables of this function. Default symbols are {u,v,w} or if 4 and more variables {u0,u1,..}.- Since:
- JavaView 3.50.002
- Version:
- 27.07.04, 1.00 created (kp)
-
getNumFunctions
public int getNumFunctions()
Get number of functions.
-
setNumFunctions
public void setNumFunctions(int numFunctions)
Set number of functions.
-
getExpressionName
public java.lang.String getExpressionName()
Get string of function if number of functions is 1.- Since:
- JavaView 3.50.002
- Version:
- 31.07.04, 1.00 created (kp)
-
setExpressionName
public void setExpressionName(java.lang.String name)
Set name of function expression.- Since:
- JavaView 3.50.002
- Version:
- 31.07.04, 1.00 created (kp)
-
getExpressionName
public java.lang.String getExpressionName(int ind)
Get string of function with indexind.
-
setExpressionName
public void setExpressionName(int ind, java.lang.String name)Set name of individual function expression.- Since:
- JavaView 3.50.002
- Version:
- 31.07.04, 1.00 created (kp)
-
getExpressionNames
public java.lang.String[] getExpressionNames()
Get string of function if number of functions is 1.- Since:
- JavaView 3.50.002
- Version:
- 31.07.04, 1.00 created (kp)
-
setExpressionNames
public void setExpressionNames(java.lang.String[] name)
Set names of all function expressions.- Since:
- JavaView 3.50.002
- Version:
- 31.07.04, 1.00 created (kp)
-
getExpressions
public java.lang.String[] getExpressions()
Get strings of all function.- Since:
- JavaView 3.50.002
- Version:
- 31.07.04, 1.00 created (kp)
-
getExpression
public java.lang.String getExpression()
Get string of function if number of functions is 1.- Since:
- JavaView 3.50.002
- Version:
- 31.07.04, 1.00 created (kp)
-
getExpression
public java.lang.String getExpression(int ind)
Get string of function with indexind.
-
setExpression
public boolean setExpression(java.lang.String expr)
Supply expression of function if number of functions is 1.- Since:
- JavaView 3.50.002
- Version:
- 31.07.04, 1.00 created (kp)
-
setExpression
public boolean setExpression(int ind, java.lang.String expr)Set string of function with indexind.String is trimmed, i.e. leading and trailing whitespace characters are removed using String.trim().
- Version:
- 22.09.04, 1.20 revised (kp) Method no longer stores default function values, use explicit setting.
01.08.04, 1.10 revised (kp) Expression string is trimmed.
-
setDefExpression
public boolean setDefExpression(int ind, java.lang.String expr)Set string of function with indexind.String is trimmed, i.e. leading and trailing whitespace characters are removed using String.trim().
- Since:
- JavaView v.3.56.003
- Version:
- 22.09.04, 1.00 created (kp)
-
setExpression
public boolean setExpression(java.lang.String expr, int ind)Deprecated. since JavaView 3.50.002, use setExpression(int, String);Set string of function with indexind.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[] exprArr)
Deprecated. since JavaView 3.50.003, use setExpressions(String []).Supply expressions of all functions.
-
setExpressions
public boolean setExpressions(java.lang.String[] exprArr)
Supply expressions of all functions.- Since:
- JavaView 3.50.003
- Version:
- 02.08.04, 1.00 created (kp) Based on earlier method setExpression(String []).
-
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(double arg0, double arg1)Evaluate a real-valued function of three variables.- Parameters:
arg0- Value of function argument.arg1- Value of function argument.- Returns:
- double Function value evaluated at 'arg'.
- Since:
- JavaView 3.99.074
- Version:
- 03.04.11, 1.00 created (kp)
-
eval
public double eval(double arg0, double arg1, double arg2)Evaluate a real-valued function of three variables.- Parameters:
arg0- Value of function argument.arg1- Value of function argument.arg2- Value of function argument.- Returns:
- double Function value evaluated at 'arg'.
- Since:
- JavaView 3.99.074
- Version:
- 03.04.11, 1.00 created (kp)
-
eval
public double eval(int ind, double arg)Evaluate a component of an m-dim functions of one variable.- Parameters:
ind- Component to evaluatearg- Value of function argument.- Returns:
- double value of function component evaluated at argument
-
eval
public boolean eval(double[] result, double arg)Evaluate an m-dim function of one variable.- Parameters:
result- Existing array to contain the computed function values.arg- Value of function argument.- Returns:
- false if an error occurred, or data is missing.
-
eval
public double eval(int ind, double[] arg)Evaluate a component of an m-dim functions of n-variables.- Parameters:
ind- Component to evaluatearg- 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.
-
eval
public double eval()
Evaluate a real-valued function of one variable.- Returns:
- double Function value evaluated at 'arg'.
- Since:
- JavaView 3.50.002
- Version:
- 31.07.04, 1.00 created (kp)
-
eval
public double eval(int ind)
Evaluate a component of an m-dim functions of n-variables'.- Parameters:
ind- Component to evaluate- Returns:
- double value of function component evaluated at argument
- Since:
- JavaView 3.50.002
- Version:
- 31.07.04, 1.00 created (kp)
-
eval
public boolean eval(double[] result)
Evaluate an m-dim functions of n-variables.- Parameters:
result- Existing array to contain the computed function values.- Returns:
- false if an error occurred, or data is missing.
- Since:
- JavaView 3.50.002
- Version:
- 31.07.04, 1.00 created (kp)
-
-
"