Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!z4g2000yqa.googlegroups.com!not-for-mail
From: free0iran <free_iran@hotmail.co.uk>
Newsgroups: comp.soft-sys.matlab
Subject: fmincon minimisation
Date: Mon, 15 Mar 2010 09:37:00 -0700 (PDT)
Organization: http://groups.google.com
Lines: 98
Message-ID: <c0e3ccdb-631d-4490-8436-90e5eec0c9f2@z4g2000yqa.googlegroups.com>
NNTP-Posting-Host: 91.106.51.240
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: posting.google.com 1268671020 31073 127.0.0.1 (15 Mar 2010 16:37:00 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 15 Mar 2010 16:37:00 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: z4g2000yqa.googlegroups.com; posting-host=91.106.51.240; 
	posting-account=kzRQJAoAAABjUTkcxSDYzAdbd7Rlo2oI
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2) 
	Gecko/20100115 Firefox/3.6,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:616956

hello.
i am using fmincon for circle packing problem. specifically fitting n
unit circle into the smallest possible larger circle so that no two
circle overlap and that all the unit circle lie entirely within the
large circle. this is the M-file for the two nonlinear constraints:

function [c,ceq] = nonlconN(x)
n=(length(x)-1)/2;
cnt=1;
for i=1:(n-1)
    for j=(i+1):n
        c(cnt)=-(x(2*i-1)-x(2*j-1))^2-(x(2*i)-x(2*j))^2+4;
        cnt=cnt+1;
    end
    c(cnt)=x(2*i-1)^2+x(2*i)^2-(x(2*n+1)-1)^2;
    cnt=cnt+1;
end
c(cnt)=x(2*n-1)^2+x(2*n)^2-(x(2*n+1)-1)^2;
ceq=[];

 the problem works if the derivative is approximated by the solver but
to see if i can get better results i want to manually supplly both the
objective and the nonlinear constraint gradient.
i have tried with the objective function gradient supplied and that
works fine too.
the problem is when i try to supply the nonlinear constraint
gradient.

this is what i wrote:

function [c,ceq,GC,GCeq] = nonlconNgrad(x)
n=(length(x)-1)/2;
cnt=1;cnt2=1
for i=1:(n-1)
    for j=(i+1):n
        c(cnt)=-(x(2*i-1)-x(2*j-1))^2-(x(2*i)-x(2*j))^2+4;
        cnt=cnt+1;
        if nargout > 2
        for t=1:(2*n+1);
            if t==(2*i-1);
                GC(t,cnt2)=-2*x(2*i-1)+2*x(2*i);
            else
                if t==2*j-1
                    GC(t,cnt2)=2*x(2*i-1)-2*x(2*j-1);
                else
                    if t==2*i
                        GC(t,cnt2)=-2*x(2*i-1)+2*x(2*j);
                    else
                        if t==2*j
                            GC(t,cnt2)=2*x(2*i)-2*x(2*j);
                        else
                            GC(t,cnt2)=0;
                        end
                    end
                end
            end
            cnt2=cnt2+1
        end

        end
    end


    c(cnt)=x(2*i-1)^2+x(2*i)^2-(x(2*n+1)-1)^2;
    cnt=cnt+1;
    if nargout>2
    for t=1:(2*n)
        if t==(2*i-1)
            GC(t,cnt2)=2*x(2*i-1);
        else
            if t==(2*i)
                GC(t,cnt2)=2*x(2*i);
            else
                GC(t,cnt2)=0;
            end
        end
        cnt2=cnt2+1;
    end
    end

end
c(cnt)=x(2*n-1)^2+x(2*n)^2-(x(2*n+1)-1)^2;
ceq=[];
if nargout>2
GC(2*n+1,cnt)=-2*x(2*n+1)+2;
GCeq=[];
end

the problem is that when i press start to run the solver once i get
messgae:

Optimization terminated: no feasible solution found. Magnitude of
search
 direction less than 2*options.TolX but constraints are not satisfied.

i tried to change the x tolerance but that did no good.

can anybody please help me?!