Optimization for finding a complex number as input

I am wondering if there is a C / C ++ library or a Matlab code method for determining real and complex numbers using a minimization solver. Here is a code snippet showing what I would like to do. Suppose, for example, that I know Utilde variables, but not x and U I want to use optimization ( fminsearch ) to determine the x and U specified by Utilde . Note that Utilde is a complex number.

 x = 1.5; U = 50 + 1i*25; x0 = [1 20]; % starting values Utilde = U * (1 / exp(2 * x)) * exp( 1i * 2 * x); xout = fminsearch(@(v)optim(v, Utilde), x0); function diff = optim(v, Utilde) x = v(1); U = v(2); diff = abs( -(Utilde/U) + (1 / exp(2 * x)) * exp( 1i * 2 * x ) ); 

The code above does not converge to the corresponding values, and xout = 1.7318 88.8760 . However, if U = 50 , which is not a complex number, then xout = 1.5000 50.0000 , which are the correct values.

Is there a way in Matlab or C / C ++ to ensure correct convergence, given Utilde as a complex number? Maybe I need to change the code above?

  • If there is no way to do this initially in Matlab, then perhaps one essence of the question is this: is there a multidimensional (i.e.Nelder-Mead or similar algorithm) that can work with real and complex inputs and outputs?

  • One more question: is the function convergent or not. I do not know if this is an algorithm or a function. Maybe I need to change something in the expression Utilde = U * (1 / exp(2 * x)) * exp( 1i * 2 * x) to make it convergent?

+6
source share
3 answers

The main problem here is that there is no single solution to this optimization or parameter setting problem. For example, if you look at the expected and actual results above, Utilde equivalent (ignoring rounding differences) for two ( x , U ) pairs, i.e.

 Utilde(x = 1.5, U = 50 + 25i) = Utilde(x = 1.7318, U = 88.8760) 

Although I have not studied it in detail, I even suspect that for any value of x you can find U that computes Utilde(x, U) = Utilde(x = 1.5, U = 50 + 25i) .

Thus, the solution here will be to further limit the problem of setting parameters, so that the solver gives any solution that can be considered acceptable. Alternatively, reformulate Utilde to have a unique meaning for any pair ( x , U ).

UPDATE, AUG 1

Given reasonable initial values, it actually seems to be sufficient to limit x real value. Performing unconditional nonlinear optimization using the diff function formulated above, I get the following result:

 x = 1.50462926953244 U = 50.6977768845879 + 24.7676554234729i diff = 3.18731710515855E-06 

However, changing the initial value to values โ€‹โ€‹more distant from the desired values โ€‹โ€‹gives different solutions, therefore, limiting x to real values โ€‹โ€‹not only provides a unique solution to the problem.

I implemented this in C # using the BOBYQA optimizer, but the numbers should be the same as above. If you want to try outside of Matlab, it should also be relatively simple to turn the C # code below into C ++ code using the std :: complex class and the (unlimited) non-linear C ++ optimizer of your choice. You can find some C ++ compatible codes that do not require gradient computation here , and there are various implementations available in Numerical Recipes. For example, you can access the C NR version online here .

For reference, here are the relevant parts of my C # code:

 class Program { private static readonly Complex Coeff = new Complex(-2.0, 2.0); private static readonly Complex UTilde0 = GetUTilde(1.5, new Complex(50.0, 25.0)); static void Main(string[] args) { double[] vars = new[] {1.0, 25.0, 0.0}; // xstart = 1.0, Ustart = 25.0 BobyqaExitStatus status = Bobyqa.FindMinimum(GetObjfnValue, vars.Length, vars); } public static Complex GetUTilde(double x, Complex U) { return U * Complex.Exp(Coeff * x); } public static double GetObjfnValue(int n, double[] vars) { double x = vars[0]; Complex U = new Complex(vars[1], vars[2]); return Complex.Abs(-UTilde0 / U + Complex.Exp(Coeff * x)); } } 
+2
source

The documentation for fminsearch says how to handle complex numbers in a section:

fminsearch minimizes only real numbers, i.e. x should consist only of real numbers, and f(x) should return real numbers. When x has complex variables, they must be broken down into real and imaginary parts.

You can use the real and imag functions to extract the real and imaginary parts, respectively.

+2
source

There seems to be no easy way to do this, even if both x and U are real numbers. The equation for Utilde not correct for the optimization problem, so it must be changed.

I tried to copy my own version of the Nelder-Mead optimization algorithm, and also try the Powell method. None of them are suitable for this problem, even when I tried to change these methods.

0
source

Source: https://habr.com/ru/post/920440/


All Articles