Solve Equation - Functions

The following functions are supported by the "Solve Equation" workflow:

Function Description
abs Absolute Value
acos Arccosine
asin Arcsine
atan Arctangent
cos Cosine
degrees Convert radians to degrees
even Rounds up to the nearest even integer
fact Factorial – Example: fact(5) = 5 * 4 * 3 * 2 * 1
gcf Greatest Common Factor (Included as an example math function)
log log(number,base)
log10 Log Base 10 of a number
max Maximum Value – Can take multiple parameters
min Minimum Value – Can take multiple parameters
neg Internal Use A negative number neg 1 = -1
odd Rounds up to the nearest odd integer
power power(a,b) = a^b
radians Convert degrees to radians
randbetween A random number between the two numbers passed – Example: randbetween(1,10)
round Rounds the number 1 to the number 2’s number of decimal places.
sign 1 if positive, 0 if 0, -1 if less than 0
sin Sine
sqrt Square Root
tan Tangent
trunc Remove anything after the decimal place.

Adding more functions
More funcitons can be added in EqOperator.cs. Just add more lines to the static constructor. There are multiple constructors for adding new functions and operators. In EqOperator.cs there are also examples. Below is an example of how to add the log function:

Operators.Add("log", new EqOperator("log", TokenCategory.Function, 2, p => Math.Log(p[1], p[0])));

Functions can also use custom methods, gcf is an example of using a function instead of a lamda expression:
/// <summary>
/// GCF is an example function to show how you can add more functions to this math library.
/// </summary>
/// <param name="p">The array of parameters</param>
/// <returns>The double result</returns>
private static double GCF(double[] p)
	var i = new int[p.Length];
	var min = 0;
	for (var j = 0; j < p.Length; j++)
		i[j] = Convert.ToInt32(Math.Truncate(p[j]));
		if (i[j] != p[j])
			throw new ArgumentException("Error: gcf paramters must be integers (whole numbers).");
		if (Math.Abs(i[j]) < min)
			min = Math.Abs(i[j]);

	int n;
	for (n = min; n > 0; n--)
		var x = n;
		if (i.All(t => x % t == 0))
			return x;
	return 1;

Last edited Jul 7, 2010 at 4:10 PM by carltoncolter, version 2


No comments yet.