how to build large objective function in Optimization Toolbox?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Alan Weiss
2017-5-11
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 个评论
Steven Lord
2017-5-11
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!