jhplot
Class F2D
- java.lang.Object
-
- jhplot.Plottable
-
- jhplot.DrawOptions
-
- jhplot.F2D
-
- All Implemented Interfaces:
- java.io.Serializable
public class F2D extends DrawOptions
Create 2D function. The function may have up to 2 independent variables: x,y. One can enabled fast math calculation using @see jhplot.HParam. For example, setting jhplot.HParam.setMath(true) makes calculation of elementary functions a factot 4-5 faster than using the standard Java Math, with precision of E-14. Operators and functions
the following operators are supported:- Addition: '2 + 2'
- Subtraction: '2 - 2'
- Multiplication: '2 * 2'
- Division: '2 / 2'
- Exponential: '2 ^ 2' or ** (raise to a power)
- Unary Minus,Plus (Sign Operators): '+2 - (-2)'
- Modulo: '2 % 2'
- abs: absolute value
- acos: arc cosine
- asin: arc sine
- atan: arc tangent
- cbrt: cubic root
- ceil: nearest upper integer
- cos: cosine
- cosh: hyperbolic cosine
- exp: euler's number raised to the power (e^x)
- floor: nearest lower integer
- log: logarithm natural (base e)
- log10: logarithm (base 10)
- sin: sine
- sinh: hyperbolic sine
- sqrt: square root
- tan: tangent
- tanh: hyperbolic tangent
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description F2D(Expression calc, double Xmin, double Xmax, double Ymin, double Ymax)
Create a function in 2D.F2D(FProxy f)
Initialize function from proxy.F2D(IFunction iname)
Create a F2D function from JAIDA IFunction.F2D(IFunction iname, double Xmin, double Xmax, double Ymin, double Ymax)
Create a F2D function from JAIDA IFunction.F2D(java.lang.String name)
Create a function in 2D for evaluation.F2D(java.lang.String name, double Xmin, double Xmax, double Ymin, double Ymax)
Build a 2D function.F2D(java.lang.String title, Expression calc, double Xmin, double Xmax, double Ymin, double Ymax)
Create a function in 2D.F2D(java.lang.String title, IFunction iname, double Xmin, double Xmax, double Ymin, double Ymax)
Create a F2D function from JAIDA IFunction.F2D(java.lang.String title, java.lang.String name)
Create new function.F2D(java.lang.String title, java.lang.String name, double Xmin, double Xmax, double Ymin, double Ymax)
Create a function in 2D.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description void
doc()
Show online documentation.boolean
elementary()
Convert this function rewrite in term of elementary functions (log, exp, frac, sqrt, implicit roots) This is useful before simplifying function.double[][]
eval(double[] x, double[] y)
Evaluate a function for an array of x-valuesdouble
eval(double x, double y)
Evaluate a function at a specific point in (x,y)boolean
expand()
Convert this function rewrite in expanded form.boolean
factorize()
Convert this function rewrite in factorized form (if can).FProxy
get()
Get the proxy of this function used for serialization and non-graphical representations.java.lang.String
getException()
If error occurs at some step, this is the way to retrieve it.H2D
getH2D(java.lang.String hname, int hbinX, double hminX, double hmaxX, int hbinY, double hminY, double hmaxY)
Generate a 2D histogram from the F2D function using a custom number of bins and given min and max values.IFunction
getIFunction()
Get Jaida functiondouble
getMaxX()
Get Max value in Xdouble
getMaxY()
Get Max value in Ydouble
getMinX()
Get Min value in Xdouble
getMinY()
Get Min value in Yjava.lang.String
getName()
Get the name of the function used for evaluationExpression
getParse()
Return parsed function.int
getPoints()
Get the number of points for evaluation of a functiondouble
integral()
Integral using fastest trapezium rule method.double
integral(double minX, double maxX, double minY, double maxY)
Integral using fastest trapezium rule method.double
integral(int N, double minX, double maxX, double minY, double maxY)
Numerical integration using trapezium rule.double
integral(int xSegs, int ySegs, double minX, double maxX, double minY, double maxY)
Finds the volume under the surface described by the function f(x, y) for a <= x <= b, c <= y <= d.boolean
isParsed()
If the function is parsed correctly, return true.boolean
numeric()
Perform some numeric substitutions.boolean
parse()
Parse the function.void
setMaxX(double max)
Set Max value in Xvoid
setMaxY(double max)
Set Max value in Yvoid
setMinX(double min)
Set Min in Xvoid
setMinY(double min)
Set Min value in Yvoid
setName(java.lang.String name)
Sets a name of the function, i.e.void
setPar(java.lang.String parameter, double value)
Replace abstract parameter with the value (double).void
setPoints(int bins)
Set the number of pointsboolean
simplify()
Try to simplify this function.java.lang.String
toJava()
Convert the function into Java code.java.lang.String
toMathML()
Convert the function into MathML form.java.lang.String
toString()
Get this function as a string.-
Methods inherited from class jhplot.DrawOptions
copyLinePars, getBinWidth, getColor, getDrawOption, getDrawOptions, getFillColor, getLegend, getLineParm, getLineStyle, getNameX, getNameY, getNameZ, getPenWidth, getSymbol, getSymbolShape, getSymbolSize, getTitle, getType, isBars, isErrX, isErrY, isFilled, printDrawOptions, printDrawOptions, setBars, setBinWidth, setColor, setDrawLine, setDrawLineKey, setDrawOption, setDrawSymbol, setErr, setErrAll, setErrColor, setErrColor, setErrColorX, setErrColorY, setErrFill, setErrFillColor, setErrFillColor, setErrSys, setErrSysFill, setErrSysFillColor, setErrSysFillColor, setErrSysX, setErrSysY, setErrTicSize, setErrX, setErrY, setFill, setFillColor, setFillColorTransparency, setGraphStyle, setLegend, setLineStyle, setNameX, setNameY, setNameZ, setPenDash, setPenDash, setPenWidth, setPenWidthErr, setPenWidthErrSys, setStyle, setSymbol, setSymbol, setSymbolSize, setTitle, setType
-
-
-
-
Constructor Detail
-
F2D
public F2D(java.lang.String name)
Create a function in 2D for evaluation. The function is not in range. The function may have up to 2 independent variables: x,y.Operators and functions
the following operators are supported:- Addition: '2 + 2'
- Subtraction: '2 - 2'
- Multiplication: '2 * 2'
- Division: '2 / 2'
- Exponential: '2 ^ 2' or ** (raise to a power)
- Unary Minus,Plus (Sign Operators): '+2 - (-2)'
- Modulo: '2 % 2'
- abs: absolute value
- acos: arc cosine
- asin: arc sine
- atan: arc tangent
- cbrt: cubic root
- ceil: nearest upper integer
- cos: cosine
- cosh: hyperbolic cosine
- exp: euler's number raised to the power (e^x)
- floor: nearest lower integer
- log: logarithm natural (base e)
- sin: sine
- sinh: hyperbolic sine
- sqrt: square root
- tan: tangent
- tanh: hyperbolic tangent
- Parameters:
name
- String representing the function
-
F2D
public F2D(java.lang.String title, java.lang.String name)
Create new function.- Parameters:
title
- titlename
- definition
-
F2D
public F2D(java.lang.String title, java.lang.String name, double Xmin, double Xmax, double Ymin, double Ymax)
Create a function in 2D. This is a ranged function. Uses 200 points between min and max value for evaluation. The function may have up to 2 independent variables in it (x,y). Operators and functions
the following operators are supported:- Addition: '2 + 2'
- Subtraction: '2 - 2'
- Multiplication: '2 * 2'
- Division: '2 / 2'
- Exponential: '2 ^ 2' or ** (raise to a power)
- Unary Minus,Plus (Sign Operators): '+2 - (-2)'
- Modulo: '2 % 2'
- abs: absolute value
- acos: arc cosine
- asin: arc sine
- atan: arc tangent
- cbrt: cubic root
- ceil: nearest upper integer
- cos: cosine
- cosh: hyperbolic cosine
- exp: euler's number raised to the power (e^x)
- floor: nearest lower integer
- log: logarithm natural (base e)
- sin: sine
- sinh: hyperbolic sine
- sqrt: square root
- tan: tangent
- tanh: hyperbolic tangent
- Parameters:
name
- String representing the function.Xmin
- Min value in XXmax
- Max value in XYmin
- Min value in YYmax
- Max value in Y
-
F2D
public F2D(java.lang.String name, double Xmin, double Xmax, double Ymin, double Ymax)
Build a 2D function. Title is set to the name. This is ranged function.- Parameters:
name
- NameXmin
- X-minXmax
- X-maxYmin
- Y-minYmax
- Y-max
-
F2D
public F2D(java.lang.String title, IFunction iname, double Xmin, double Xmax, double Ymin, double Ymax)
Create a F2D function from JAIDA IFunction. By default, 500 points for evaluation are used. Ranged function.- Parameters:
title
- Titlename
- new function nameiname
- input IFunctionXmin
- Min X valueXmax
- Max X valueYmin
- Min Y valueYmax
- Max Y value
-
F2D
public F2D(java.lang.String title, Expression calc, double Xmin, double Xmax, double Ymin, double Ymax)
Create a function in 2D. 500 points are used between Min and Max for evaluation. The function may have x as independent variable. Make sure that expression has 2 variables, x and y.- Parameters:
title
- Titlefunction
- Expression after parsing and buildingXmin
- Min X valueXmax
- Max X valueYmin
- Min Y valueYmax
- Max Y value
-
F2D
public F2D(Expression calc, double Xmin, double Xmax, double Ymin, double Ymax)
Create a function in 2D. 200 points are used between Min and Max for evaluation. The function may have x as independent variable. Make sure that expression has 2 variables, x and y.- Parameters:
title
- Titlefunction
- Expression after parsing and buildingXmin
- Min X valueXmax
- Max X valueYmin
- Min Y valueYmax
- Max Y value
-
F2D
public F2D(IFunction iname)
Create a F2D function from JAIDA IFunction. By default, 500 points for evaluation are used. Unranged function.- Parameters:
iname
-
-
F2D
public F2D(FProxy f)
Initialize function from proxy.- Parameters:
f
-
-
F2D
public F2D(IFunction iname, double Xmin, double Xmax, double Ymin, double Ymax)
Create a F2D function from JAIDA IFunction.- Parameters:
iname
- input IFunctionXmin
- Min X valueXmax
- Max X valueYmin
- Min Y valueYmax
- Max Y value
-
-
Method Detail
-
eval
public double eval(double x, double y)
Evaluate a function at a specific point in (x,y)- Parameters:
x
- value in x for evaluationy
- value in y for evaluation- Returns:
- function value at (x,y)
-
getIFunction
public IFunction getIFunction()
Get Jaida function- Returns:
-
eval
public double[][] eval(double[] x, double[] y)
Evaluate a function for an array of x-values- Parameters:
x
- array of values in x for evaluationy
- array of values in y for evaluation- Returns:
- array of function values
-
setMinX
public void setMinX(double min)
Set Min in X- Parameters:
min
- Min value
-
parse
public boolean parse()
Parse the function.- Returns:
- true if parsed without problems.
-
getMinX
public double getMinX()
Get Min value in X- Returns:
- Min value in X
-
setMinY
public void setMinY(double min)
Set Min value in Y- Parameters:
min
- Min value in Y
-
doc
public void doc()
Show online documentation.
-
getMinY
public double getMinY()
Get Min value in Y- Returns:
- Min value in Y
-
setMaxX
public void setMaxX(double max)
Set Max value in X- Parameters:
max
- Max value in X
-
setName
public void setName(java.lang.String name)
Sets a name of the function, i.e. what will be used for evaluation- Parameters:
name
- Name
-
getName
public java.lang.String getName()
Get the name of the function used for evaluation- Returns:
- Name
-
getMaxX
public double getMaxX()
Get Max value in X- Returns:
- Max value in X
-
setMaxY
public void setMaxY(double max)
Set Max value in Y- Parameters:
max
- Max value in Y
-
getMaxY
public double getMaxY()
Get Max value in Y- Returns:
- Max value in Y
-
setPoints
public void setPoints(int bins)
Set the number of points- Parameters:
bins
- Number of points
-
setPar
public void setPar(java.lang.String parameter, double value)
Replace abstract parameter with the value (double). Case sensitive!- Parameters:
parameter
- parameter namevalue
- value to be inserted
-
getPoints
public int getPoints()
Get the number of points for evaluation of a function- Returns:
- Number of points
-
integral
public double integral(int N, double minX, double maxX, double minY, double maxY)
Numerical integration using trapezium rule.- Parameters:
N
- the number of strips to use for integration (in X and Y the same)minX
- the first ordinate in X.maxX
- the last ordinate in X.minY
- the first ordinate in X.maxY
- the last ordinate in Y.- Returns:
- integral
-
integral
public double integral(double minX, double maxX, double minY, double maxY)
Integral using fastest trapezium rule method. It uses the default number of points (500).- Parameters:
minX
- the first ordinate in X.maxX
- the last ordinate in X.minY
- the first ordinate in X.maxY
- the last ordinate in Y.
-
simplify
public boolean simplify()
Try to simplify this function. It is often useful to rewrite an expression in term of elementary functions (log, exp, frac, sqrt, implicit roots), using the "elementary()" before simplifying it. Retrieve the simplified name as a string using getName() method.- Returns:
- false if error occurs. Retrieve this error as a string using getException().
-
getException
public java.lang.String getException()
If error occurs at some step, this is the way to retrieve it.- Returns:
- last exception happened in any method of this class.
-
getParse
public Expression getParse()
Return parsed function. One can evaluate it as "calculate()".- Returns:
- function
-
getH2D
public H2D getH2D(java.lang.String hname, int hbinX, double hminX, double hmaxX, int hbinY, double hminY, double hmaxY)
Generate a 2D histogram from the F2D function using a custom number of bins and given min and max values.- Parameters:
hname
- histogram namehbinX
- number of X binshminX
- min value in XhmaxX
- max value in XhbinY
- number of bins in YhminY
- min value in YhmaxY
- max value in Y- Returns:
- 2D histogram from the function
-
integral
public double integral()
Integral using fastest trapezium rule method. This function return non-zero if it the range was defined during the initialization. The default number of points is 500. Increase it if needed more precision.- Returns:
- integral in the range defined during the initialization.
-
integral
public double integral(int xSegs, int ySegs, double minX, double maxX, double minY, double maxY)
Finds the volume under the surface described by the function f(x, y) for a <= x <= b, c <= y <= d. It uses the trapezoid rule. Using xSegs number of segments across the x axis and ySegs number of segments across the y axis.- Parameters:
xSegs
- The number of segments in the x axis.ySegs
- The number of segments in the y axis.minX
- The lower bound of x.maxX
- The upper bound of x.minX
- The lower bound of y.maxY
- The upper bound of y.- Returns:
- The volume under the function f(x, y).
-
isParsed
public boolean isParsed()
If the function is parsed correctly, return true. Use this check before drawing it.- Returns:
- true if parsed.
-
toMathML
public java.lang.String toMathML()
Convert the function into MathML form.- Returns:
- String representing this function in MathML.
-
toJava
public java.lang.String toJava()
Convert the function into Java code.- Returns:
- String representing this function in Java.
-
elementary
public boolean elementary()
Convert this function rewrite in term of elementary functions (log, exp, frac, sqrt, implicit roots) This is useful before simplifying function. Retrieve the simplified name as a string using getName() method.- Returns:
- false if error occurs. Retrieve this error as a string using getException().
-
expand
public boolean expand()
Convert this function rewrite in expanded form. Retrieve the expanded name as a string using getName() method.- Returns:
- false if error occurs. Retrieve this error as a string using getException().
-
factorize
public boolean factorize()
Convert this function rewrite in factorized form (if can). Retrieve the expanded name as a string using getName() method.- Returns:
- false if error occurs. Retrieve this error as a string using getException().
-
numeric
public boolean numeric()
Perform some numeric substitutions. Examples: exp(1) should be 2.71828182, "pi" should be 3.14159 etc. Retrieve the expanded name as a string using getName() method.- Returns:
- false if error occurs. Retrieve this error as a string using getException().
-
get
public FProxy get()
Get the proxy of this function used for serialization and non-graphical representations.- Parameters:
proxy
- proxy of this function.
-
toString
public java.lang.String toString()
Get this function as a string.- Overrides:
toString
in classjava.lang.Object
- Returns:
- Convert to string.
-
-
DMelt 3.0 © DataMelt by jWork.ORG