Script Function Reference

Function Reference >Script Function Reference >Function Manipulation>createFunction

createFunction

createFunction creates a new calculator function.

createFunction(type, name, parameters, equations...)

Parameters

type is a string representing the type of function to create. The allowed values are detailed below.
name is a string for the name of the function to create.
parameters is a string representing the parameters for the function. Multiple parameters are seperated by a ','.
equations are string values defining the function. The number of equations depends on the type. This is detailed below.

Return Value

createFunction returns the function created in a function table format. It return nil if the function could not be created.

Additional Information

The possible values for type are.
  • "user" - This is a function that isn't graphed anywhere. It has one equation.
  • "xy" - This is a standard cartesian graph. parameters can be either "x" or "y". It has one equation.
  • "polar" - This is a polar graph. parameters has to be "a". It has one equation.
  • "para2d" - This is a 2D parametric graph. parameters has to be "t". It has two equations.
  • "xyz" - This is a 3D cartesian graph. parameters can be "x,y", "y,z", or "x,z". It has one equation.
  • "para3d" - This is a 3D parametric equation. parameters can be "u,v" or "t". It has three equations.
  • "2dplot" - This is a 2D plot. parameters has to be an empty string "". It has two equations that need to evaluate to a list.
Possible reasons for the function to fail is an invalid type, a function with that name already exists, invalid parameters, or the wrong number of equations.

Example

function example()
	createFunction("xy", "parabola", "y", "y^2")
	createFunction("para3d", "sphere", "u,v", "cos(u)*cos(v)", "sin(u)*cos(v)", "sin(v)")
	fn = createFunction("user", "dist", "x,y", "sqrt(x^2+y^2)")
	r = evalFunction(fn, 3, 4)
	outputString("value="..value.r.."\n")
end