Error of "Too many input arguements"
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Sean de Wolski
on 25 Sep 2014
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
John D'Errico
on 25 Sep 2014
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.
See Also
Categories
Find more on Linear Least Squares in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!