0
votes

I want to minimize a very simple function.

function z=f(x)
    f=(x(1)-2)^2+(x(2)-1)^2
end

and I write this in matlab command window:

>> [x fval]=ga(@f,2)

But I get this error:

??? Error using ==> ga

Too many input arguments.

Any suggestions to fix this problem?

1
What does which ga return? - Daniel
@DanielR C:\Users\student\Documents\MATLAB\ga.m - ali meghdadi
This file overwrites the build in. Delete it. - Daniel
@DanielR Which file should he delete? You mean ga.m? - melmi

1 Answers

2
votes

If you have multiple ga.m, the build in and your own ga.m in C:\Users\student\Documents\MATLAB\ga.m, matlab uses

  1. Files in the current directory
  2. Files in the order they are placed on path

Obviously, your ga.m is first in order, which causes Matlab to call it instead of the buildin. Either fix the path settings, or delete C:\Users\student\Documents\MATLAB\ga.m