Is it possible to use the optimization function fmincon with a Matlab defined function?
I wrote a function where I give few constant parameters (real or complex) and for now, every time I change these parameters, the result changes (you don't say).
[output1, output2] = my_function(input1,input2,input3,input4)
I saw that fmincon function allows to find the optimum result with a given constraint. Let's say that I want to find the optimum output acting only on input1 and keeping constant all the others inputs. Is it possible to define something like
fmincon(@(input1)my_function,[1,2],[],mean)
for input1 that goes from 1 to 2 for the best value mean, where mean is the mean value of some other results.
I know that is a quite vague question but I'm not able to give a minimum example, since function makes a lot of things
The first attept with multiple outputs gave me the error Only functions can return multiple values.
Then I tried with only one output and if I use
output1 = @(input1)function(input2,input3);
fmincon(@output1,[1,2],[],mean)
I get the error
Error: "output1" was previously used as a variable, conflicting with its use here as the name of a function or command. See "How MATLAB Recognizes Command Syntax" in the MATLAB documentation for details.
With fmincon(@my_function,[1,2],[],mean) I get Not enough input arguments.
fminconand its just bad use of MATLAB syntax. you can not use the wordfunctionas it is reserved. Use something else likemy_fun. Similarly, anonymous functions ( e.g.@(input1) sum(input1)) only output 1 value, so you may need to create a fucntion in a separate file that does what you want. I can not help more without a real example, a real minimal reproducible example - Ander Biguri