External Functions

These are java class files which descend from the Functions/ExternalFunction class file. They must overide the evaluate function.

       
package MathLib.Functions.General;

import MathLib.Tokens.*;
import MathLib.Functions.ExternalFunction;

/**An external function for computing a mesh of a matrix  */
public class template extends ExternalFunction
{
    /**returns two  matrices 
     * @param operands[0] = x values (e.g. [-2:0.2:2]) 
     * @param operands[1] = y values (e.g. [-2:0.2:2])
     * @return [X,Y] as matrices                                 */
    public OperandToken evaluate(Token[] operands)
    {

        // one operand (e.g. [x,y]=template([-2:0.2:2],[-2:0.2:2]) )
        if (getNArgIn(operands)!=2)
            throwMathLibException("template: number of input arguments != 2");

        // Check number of return arguments
        if (getNoOfLeftHandArguments()!=2)
            throwMathLibException("template: number of output arguments != 2");

        if ( !(operands[0] instanceof NumberToken) ||
             !(operands[0] instanceof NumberToken)   )
            throwMathLibException("template: works only on numbers");

        // get data from arguments
        double[][] x =  ((NumberToken)operands[0]).getValues();
        double[][] y =  ((NumberToken)operands[1]).getValues();

        if ((x.length != 1) ||
            (y.length != 1)    )
            throwMathLibException("template: works only row vectors");

        int sizeX = x[0].length;
        int sizeY = y[0].length;
        
        double[][] X = new double[sizeY][sizeX];
        double[][] Y = new double[sizeY][sizeX];
        
        for (int i=0; i<sizeY; i++)
        {
        	for (int j=0; j<sizeX; j++)
            {
            	X[i][j] = x[0][j];
                Y[i][j] = y[0][i];
            }
        } 

  	OperandToken values[][] = new OperandToken[1][2];
	values[0][0] = new NumberToken(X);
	values[0][1] = new NumberToken(Y);
	return new MatrixToken( values );

    } // end eval
}

/*
@GROUP
General
@SYNTAX
answer = template (value)
@DOC
Returns the sign of value.
@EXAMPLES
SIGN(-10)=-1
SIGN(10)=1
@NOTES
@SEE
template
*/

  
public int getNoOfLeftHandArguments()
protected int getNArgOut()
protected int getNArgIn(Token[] operands)
public void setNoOfLeftHandArguments(int _number)

public void throwMathLibException(String errorMessage)
public void debugLine(String s)
 
 
RootObject.java
protected final VariableList getVariables()
protected final VariableList getGlobalVariables()
protected final Variable getVariable(String name)
protected final ContextList getContextList()
protected final Interpreter getInterpreter()
public final FunctionManager getFunctionManager()
protected jmathlib.plugins.PluginsManager getPluginsManager()
protected File getWorkingDirectory()
protected void setWorkingDirectory(File _workingDir)
protected jmathlib.core.graphics.GraphicsManager getGraphicsManager()