net.sourceforge.webcompmath.functions
Class NumMinMaxParser

java.lang.Object
  extended by net.sourceforge.webcompmath.functions.NumMinMaxParser
All Implemented Interfaces:
java.io.Serializable, MathObject, ParserExtension

public class NumMinMaxParser
extends java.lang.Object
implements ParserExtension

The NumMinMaxParser class makes it possible to use numerical minimums and maximums, such as numMin(xx,0,5,xx^2) in a Parser. The numerical min or max psedu-function has four parameters: (1) The variable, which must be an identifier and should be different than other variables registered with the parser; (2) The lower limit for the min/max, given as an expression (which can involve variables); (3) The upper limit for the min/max, given as an expression (which can involve variables); and (4) the expression over which to find the min or max. The expression in the fourth parameter can (and presumably will) use the variable (as well as other identifiers known to the parser).

The created psuedo function divides the interval into 1000 subintervals. It then checks the value of the derivative of the expression at the endpoints of each subinterval to see if a local minimum/maximum might be in the interval. If so, it hunts recursively for that local min/max, else it uses the min/max of the two subinterval endpoints. The function then returns the min/max of all 1000 subinterval min/max's.

To use numerical min with a Parser p, just say p.add(new NumMinMaxParser(NumMinParser.MIN)). It's unlikely that you will ever need to do anything else with NumMinMaxParsers. If you want to use a name other than "numMin" or "numMax", you can change the name after creating the NumMinMaxParser object but before adding it to a parser.

See Also:
Serialized Form

Nested Class Summary
static class NumMinMaxParser.MinMaxType
          The type of parser to create
 
Constructor Summary
NumMinMaxParser(NumMinMaxParser.MinMaxType t)
          Constructor
 
Method Summary
 void doParse(Parser parser, ParserContext context)
          When the name of this ParserExtension is encountered by a parser with which the extension is registered, the parser calls this routine to parse the subexpression.
 java.lang.String getName()
          Get the name, which will be used in place of "numMin" or "numMax" in expressions.
 void setName(java.lang.String name)
          Set the name, which will be used in place of "numMin" or "numMax" in expressions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumMinMaxParser

public NumMinMaxParser(NumMinMaxParser.MinMaxType t)
Constructor

Parameters:
t - the type, either MinMaxType.Min or MinMaxType.Max
Method Detail

setName

public void setName(java.lang.String name)
Set the name, which will be used in place of "numMin" or "numMax" in expressions. This should not be done after the NumMinMaxParser has been added to a Parser.

Specified by:
setName in interface MathObject
Parameters:
name - name of numerical min/max

getName

public java.lang.String getName()
Get the name, which will be used in place of "numMin" or "numMax" in expressions.

Specified by:
getName in interface MathObject
Returns:
name of min/max

doParse

public void doParse(Parser parser,
                    ParserContext context)
When the name of this ParserExtension is encountered by a parser with which the extension is registered, the parser calls this routine to parse the subexpression. The subexpression has the form ( , , , ). This method is not meant to be called directly

Specified by:
doParse in interface ParserExtension
Parameters:
parser - parser to use
context - context to use