Non-linear optimization

I have an equation that I would like to maximize. Does anyone know of any routines for Xojo similar to the solver in Excel, or just a simple maximization routine?

How many input parameters do you need to optimize, just one, or several?
If it’s just a single parameter, then you can probably use the secant method.
If you have many parameters, then you may want to try something like the Nelder-Mead method.
I’ve coded the Nelder-Mead method in LibreOffice Basic. So, it would be relatively easy to port it to Xojo. In fact it’s on my to do list.

Hi Robert

I will write the secant method in Xojo and post it here for others. Thanks for the suggestion.

Thinking about this a bit more, the secant method is a root finding algorithm, not an optimization method. It may not necessarily find the min or max of a function. So, depending on what you need to do, it may not be appropriate. It will find a minimum (or maximum) if you take the derivative of your function and then use the secant method on it to find the root(s) of the derivative, but there may be better methods.

What is the equation?

If you’ve got an equation you can just differentiate it and look for the stationary points. There are a whole bunch of different optimisation methods for direct search on systems where an equation isn’t available, but they depend on what sort of system you are dealing with (e.g. is it multi-modal).

Bryan, will be glad to get the xojo secant code on the forum to be gain full for others.

@Djamel_AIT_AMRANE

I don’t have a secant method written in Xojo, however if you are using Xojo Web, you can use ExecuteJavaScript to call math.sec(x) (see math.js | an extensive math library for JavaScript and Node.js).

As Robert Weaver noted secant may or may not be an appropriate approach to min/max goal seek scenarios.

You may prefer to use Xojo Office Automation (see https://documentation.xojo.com/topics/office_automation/controlling_microsoft_office_from_your_app.html) to set, calculate and read the results obtained using Excel - Goal Seek, from within Xojo. I found this a nice reference for the VBA needed to use goal seek (see Excel Goal Seek And GoalSeek VBA Method: Tutorial With Examples).

I hope that helps.

Hi Andrew,
Bryan said : I will write the secant method in Xojo and post it here for others. Thanks for the suggestion.
if is done, it will be gain full …
Any way, it will be interesting if any xojo coder develops a plugin for numerical analysis, and i greet in passing Robert M Delaney for his free Matrix Plugin.

Hi,
I mean a method to find a root ( optimization non-linear) it’s the fields of the numerical analysis.
I have found the code in other language and convert it to Xojo.
I tried to post it in xojo forum but Binary Project is not allowed.