how to build large objective function in Optimization Toolbox?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
chang shu
am 11 Mai 2017
Kommentiert: chang shu
am 11 Mai 2017
i have an optimization problem!
GRID is a 36*400 matrix. TT is a 36*1 matrix.
my objective fuction is wrote as
function yy = GAFunction(xx)
global GRID TT
yy = norm(GRID * xx - TT );
end
i want to solve xx using GA, fminunc,etc
when i run
GAResult = particleswarm(GAFunction,400);
or
x0 = ones(400,1);
newton = fminunc(@(x)GAFunction,x0)
it always show error
Not enough input arguments.
Error in GAFunction (line 11)
yy = norm(GRID * xx - TT );
how to build large objective function ? thank you
0 Kommentare
Akzeptierte Antwort
Alan Weiss
am 11 Mai 2017
I don't know why you don't just use
x = GRID\TT
but you probably have a different problem in mind that you didn't tell us.
Global variables are troublesome, I suggest that you avoid using them. Learn how to pass extra parameters using function handles or nested functions. Also, you might want to ensure that your xx variable has column orientation by changing GAFunction to use xx(:):
yy = norm(GRID * xx(:) - TT );
Alan Weiss
MATLAB mathematical toolbox documentation
2 Kommentare
Steven Lord
am 11 Mai 2017
If you must use this formulation instead of backslash as Alan suggested, the cause of the error is here:
newton = fminunc(@(x)GAFunction,x0)
fminunc will call the anonymous function with one input argument and one output argument. The anonymous function will call GAFunction with zero input arguments and one output argument and will return the output it received from GAFunction as its output.
But the GAFunction needs to be called with one input argument. If you call it with zero input arguments, it doesn't know what to compute when it tries to compute GRID*xx. This is why it throws an error. In this case, you could modify the anonymous function, or use a regular function handle.
newton = fminunc(@(x)GAFunction(x),x0)
newton = fminunc(@GAFunction,x0)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Genetic Algorithm finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!