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

采纳的回答

Alan Weiss
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
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)
chang shu
chang shu 2017-5-11
thank you
Alan Weiss & Steven Lord
GRID is a large sparse matrix
the result using x = GRID\TT isn't very good
so i want to try global optimization.
Matlab have serval fuctions to solve large sparse matrix , like
bicg, bicgstab
but these functions have limitations: The n-by-n coefficient matrix A must be square.
GRID is a 36*400 matrix
how can I use bicg to solve
GRID*x = TT
Regards

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!