Optima - a custom function for finding minima and maxima
- September 13, 2022
- 3 replies
- 3009 views
Greetings,
Across all industries, when we do math we often want to find the minimum or maximum point of a function. There are many ways, but the most reliable is to do it iteratively. I have built a function that does this. Attached is the function itself. Put it in a closed area at the start of your template so that you can always call it.
The inputs of optima(f,x0,xf) are any single variable function "f", and the starting value "x0" and ending value "xf" of the domain of that function. It outputs the x value of the function at its maxima, the value at that x value, the x value of the minima, and the value of the function at its minima. It finds absolute maxima and minima of the function only. You can make a multivariable function be single variable by defining a new function of a single variable, where the other inputs are all constants. For example, f(x)=g(x,c1,c2,c3)
This is the interesting part: To make it run quickly but still get a precise answer, I split the process into two parts. The program splits the domain into 1000 increments and looks for the maxima and minima, and then it zooms in on the x value and repeats this process with a new, tighter domain centered at the x value of the found minima/maxima.
I have also built in a help feature where if you enter "?" into any input, it displays an explanation of how the function works. I make this feature standard on my custom functions now.
Please, tell me what you think? Is it useful? Redundant with something else?
Any input is welcome. Thank you.
PS. For users not using Prime 8, here is what it looks like:



