How to create a multivariable function for used in fminsearch

7 次查看(过去 30 天)
Hi,
I have a function with 200 variables. Now these need to be in the form x(1), x(2) ...... x(200) and to be used as. And some time my number of variables change based on my input generally varying in between 100-200. How can I place such symbolic expression like x(n) in a matrix form to be used for generating functions to bu used in fminsearch.
  1 个评论
Alexandra Harkai
Alexandra Harkai 2017-3-3
The number of design variables (in this case 200) is not meant to change in an optimisation like fmincon. It sounds like your minimisation problem may not be well defined.
It is easier to help if you provide more details on what the optimisation details are, for example, what is the objective function.

请先登录,再进行评论。

回答(2 个)

John D'Errico
John D'Errico 2017-3-3
编辑:John D'Errico 2017-3-3
NO. You will NEVER be able to use fminsearch on a 200 variable problem. It will essentially never be able to search the space to your satisfaction.
Use an optimizer that is designed to solve larger problems. Fminsearch works reasonably well on small problems, with up to around 6 variables as my usual upper limit, although sometimes you might go a bit higher than that, perhaps to as many as 10 variables. 200 (even 100) is wildly beyond the capabilities of fminsearch. You will be wasting your time if you try.
  2 个评论
John D'Errico
John D'Errico 2017-3-4
This is a problem that may grow exponentially (or worse!) with dimension. A simple way to appreciate why is to see that a basic dissection of the n-hypercube into simplexes will result in factorial(n) different simplexes. Worse, see that factorial(n) actually grows faster than exp(n). (Look at Stirling's approximation for the factorial to see how it grows.)
So to fully explore an n-dimensional space, a simplex does very poorly in high dimensions.

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2017-3-3
Example:
nvar = randi([100 200]);
y = randn(1, nvar);
x = sym('x', [1, nvar]);
F = @(x) sin(x).*cos(2*x); %function being minimized
funsym = sum((F(x)-y).^2); %least squared minimization
f = matlabFunction(funsym, 'Vars', {x}); %numeric function with vector input
x0 = rand(1, nvar) * 100 - 50; %starting point
bestx = fminsearch(f, x0, struct('MaxFunEvals', 100000, 'MaxIter', 100000) );
(Realistically you won't get anywhere useful on this particular function.)
Remember that systematically evaluating even just two different positions for each variable requires 2^nvar function evaluations, which is probably not realistic for nvar > 34 or so.

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by