Error of "Too many input arguements"

i would like to do optimization to the following. I would like to randomly generate two integers from the range -5.0 to 5.0 and then take square of the two integers separately and sum them up finally. The optimal solution for this function should be 0.0
function result=minsum()
x=randi([-5 5],1,2);
result=sum(x.^2);
end
I don't know if my codes are correct. When i tried to use the optimization tools it said "too many input arguements" I don't know how to solve the problem.

Answers (1)

If you want to optimize two numbers between -5 and 5, you shouldn't be using rand but instead letting the optimizer find them.
Here, I'll use random starting points but the optimizer will converge to 0,0
[xopt, fval] = fmincon(@(x)sum(x.^2),randi([-5 5],1,2),[],[],[],[],[-5 -5],[5 5])

1 Comment

Just to add a clarifying point to a valid answer, the reason why Ellen gets an error of "too many input arguments" is that her function has NO input arguments.

Sign in to comment.

Tags

Asked:

on 25 Sep 2014

Commented:

on 25 Sep 2014

Community Treasure Hunt

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

Start Hunting!