how to build large objective function in Optimization Toolbox?

2 views (last 30 days)
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

Accepted Answer

Alan Weiss
Alan Weiss on 11 May 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 Comments
Steven Lord
Steven Lord on 11 May 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)
chang shu
chang shu on 11 May 2017
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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!