Error in the following problem input(s): nonlcon: Not enough input arguments.
Show older comments
Hello I am trying to use the optimization toolbox in MATLAB and in particular fmincon.
my objective function is:
function f = circle(x)
for i = 1:2:5;
xi = x(i);
end
for j = 2:2:6;
xj = x(j);
end
f = (xi.^2 + xj.^2)^0.5;
my nonlinear constraints function is:
function [c, ceq] = disk(x)
x1 = x(1);
x2 = x(2);
x3 = x(3);
x4 = x(4);
x5 = x(5);
x6 = x(6);
c(1) = -(x6 - x4)^2 - (x5 - x3)^2 - 4; % non-convex constraints
c(2) = x3.^2 + x4.^2 - ((x1.^2 + x2.^2)^0.5 - 1)^2; %convex non-linear constraints
c(3) = x5.^2 + x6.^2 - ((x1.^2 + x2.^2)^0.5 - 1)^2;
ceq = []; % the empty equality constraints.
but i get the error message above
can anyone help me please
many thanks
7 Comments
Walter Roberson
on 26 Mar 2016
Please show your call to fmincon
Walter Roberson
on 26 Mar 2016
Please note that your code
for i = 1:2:5;
xi = x(i);
end
is equivalent to
xi = x(5);
If that is what you want then please write it in the straight-forward way.
Perhaps what you want is
xi = x(1:2:5);
xj = x(2:2:6);
alan
on 27 Mar 2016
Edited: Walter Roberson
on 27 Mar 2016
alan
on 27 Mar 2016
Edited: Walter Roberson
on 27 Mar 2016
Walter Roberson
on 27 Mar 2016
Please confirm that you stored your function circle in a file named circle.m and that you stored your function disk in a file named disk.m, and that both files are on your MATLAB path? At the command line, command
cd
which circle
which disk
to see where it thinks you are and where it thinks circle and disk are. You might need to cd to the directory that you stored circle.m and disk.m in.
alan
on 27 Mar 2016
alan
on 28 Mar 2016
Answers (1)
Walter Roberson
on 28 Mar 2016
0 votes
Your functions expect x to be a vector of length 6, but you are using a starting point which has only 2 elements. Your starting point needs to be the same length as the number of elements in the vector.
5 Comments
alan
on 28 Mar 2016
Walter Roberson
on 28 Mar 2016
Please show your current code.
alan
on 28 Mar 2016
Edited: Walter Roberson
on 1 Apr 2016
alan
on 28 Mar 2016
Walter Roberson
on 1 Apr 2016
If x is the list of centers, then you need to calculate the pairwise distances between the centers and ensure that they are all at least 2, and you need to calculate the smallest circle that can contain those centers, and the radius of that circle is what the objective function needs to return.
The pairwise distance can be done with pdist() from the Stats toolbox, or you can do the calculation yourself to save on overhead.
The smallest containing circle, I am not sure of. Perhaps if you calculate the maximum distance between any of the centers and the centroid of the centers, and then add 1 (the unit radius) ?
Categories
Find more on Choose a Solver 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!