net.moioli.drawables
Class ParsedFunction
java.lang.Object
net.moioli.drawables.AbstractDrawableFunction
net.moioli.drawables.ParsedFunction
- All Implemented Interfaces:
- DrawableI, FunctionI
public class ParsedFunction
- extends AbstractDrawableFunction
This class provides a quick way to implement mathematical functions: parsing
them from strings. Just pass a string like "x^2+sin(x)" to the constructor
and you'll get a drawable function to add to your DefaultChart.
The parsing is done with the JEP parser, so strings should follow JEP's
syntax.
- Version:
- 2005/10/5
- Author:
- Silvio Moioli
- See Also:
JEP
Constructor Summary |
ParsedFunction(java.lang.String s)
Constructs a new function with the given string. |
Method Summary |
double |
f(double x)
Returns the y value corresponding to the specified x. |
java.lang.String |
toString()
Returns a string describing this function. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
ParsedFunction
public ParsedFunction(java.lang.String s)
throws org.nfunk.jep.ParseException
- Constructs a new function with the given string. The string should follow
JEP's syntax.
- Parameters:
s
- the string to be parsed
- Throws:
org.nfunk.jep.ParseException
- if the string cannot be parsed by JEP- See Also:
JEP
f
public double f(double x)
- Returns the y value corresponding to the specified x.
- Specified by:
f
in interface FunctionI
- Specified by:
f
in class AbstractDrawableFunction
- Parameters:
x
- the abscissa
- Returns:
- the ordinate
- See Also:
FunctionI.f(double)
toString
public java.lang.String toString()
- Returns a string describing this function.
- Overrides:
toString
in class java.lang.Object
- Returns:
- a string describing this function