2

I have a cyclic program in C++ which includes composing of a function (every time it is different) and further minimization of it. Composing of a function is implemented with GiNaC package (symbolic expressions). I tried to minimize functions using Matlab fmincon function but it ate all the memory while converting string to lambda function (functions are rather complicated). And I couldn't manage to export function from C++ to Matlab in any way but as a string. Is there any way to compose a complicated function (3 variables, sin-cos-square root etc.) and minimize it without determing gradient by myself because I don't know how functions look before running the program? I also looked at NLopt and as I understood it requires gradients to be writte by programmer.

  • Could you give more detail? If the functions are composed with GiNaC, why don't you differentiate them with [it](http://www.ginac.de/tutorial/#Symbolic-differentiation)? – Mankka Nov 17 '15 at 12:19

1 Answers1

1

Most optimization algorithms do require the gradient. However, if it's impossible to 'know' it directly, you may evaluate it considering a small increment of every coordinate. If your F function depends on coordinates of x vector, you may approximate the i's component of you gradient vector G as

x1 = x;
x1[i] += dx;
G[i] = (F(x1) - F(x))/dx;

where dx is some small increment. Although such a calculation is approximate it's usually absolutely good for a minimum finding provided that dx is small enough.

AndreyS Scherbakov
  • 2,674
  • 2
  • 20
  • 27