All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.lsmp.djep.xjep.function.MaxArg Maven / Gradle / Ivy

Go to download

JEP is a Java library for parsing and evaluating mathematical expressions.

There is a newer version: 2.4.2
Show newest version
/* @author rich
 * Created on 10-Sep-2004
 */
package org.lsmp.djep.xjep.function;


import org.nfunk.jep.*;
import org.nfunk.jep.function.*;

/**
 * @author Rich Morris
 * Created on 10-Sep-2004
 */
public class MaxArg extends SumType {

	static Comparative comp = new Comparative(Comparative.LE);

	public MaxArg() {
		super("MaxArg");
	}

	public Object evaluate(Object[] elements) throws ParseException {
		throw new ParseException("MaxArg: call to evaluate(Object[] elements) should not have happened.");
	}

	public Object evaluate(
		Node node,
		Variable var,
		double min,
		double max,
		double inc,
		EvaluatorI pv)
		throws ParseException {

			int i=0;
			double val;
			Object maxVal=null;
			Object maxArg=null;
			for(i=0,val=min;val<=max;++i,val=min+i*inc)
			{
				Object curArg = new Double(val); 
				var.setValue(curArg);
				
				Object res = pv.eval(node);
				if(i==0)
				{
					maxVal = res;
					maxArg = curArg;
				}
				else if(comp.gt(res,maxVal))
				{
					maxVal = res;
					maxArg = curArg;
				}
			}
			return maxArg;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy