Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
My Fmincon doesn't work in the program.

Subject: My Fmincon doesn't work in the program.

From: lovish

Date: 15 Apr, 2009 05:13:01

Message: 1 of 1

n=input('Enter the no. of nodes');
s=input('Enter the no. of sources');
r=rand(n,2);
r=r.*10;
r=ceil(r)
y='Y';
L=[];
hold on
plot(r(:,1),r(:,2),'rs');
while(y~='N')
    l=input('Enter the capacity and its link');
    L=[L;l];
    y=input('Is there any more links (Y/N)');
end
L;
p=2;
A=ones(n,n);
C=cell(size(A));
for i=1:s
    fprintf('Enter the nodes through which source %d passes',i);
    l=input('');
    p=p+1;
    for j=1:length(l)-1
        C{l(j),l(j+1)}=[C{l(j),l(j+1)} i];
        X=[r(l(j),1) r(l(j+1),1)];
        Y=[r(l(j),2) r(l(j+1),2)];
        line(X,Y,'LineWidth',p);
    end
end
C;

[r,c]=size(L);
M=zeros(r,s);
p=1;
for i=1:r
   
    if(isempty(C{L(i,2),L(i,3)}))
        Y=C{L(i,3),L(i,2)};
    else
        Y=C{L(i,2),L(i,3)};
    end
 for k=1:length(Y)
    M(p,Y(k))=1;
               
 end
   p=p+1;
end
M;
Capacities=L(:,1);



% f=objfun(x)
% objfun(M,Capacities,x)

f=@(x)-log(x(1)+x(4))+-log(x(2))-log(x(3));


[x1,fval]=fmincon(f,x,M,Capacities)

>> x=[0.1 0.1 0.1]

x =

    0.1000 0.1000 0.1000

>> Project(x)
Enter the no. of nodes3
Enter the no. of sources3

r =

     9 10
    10 7
     2 1

Enter the capacity and its link[1 1 2]
Is there any more links (Y/N)'Y'
Enter the capacity and its link[1 2 3]
Is there any more links (Y/N)'N'
Enter the nodes through which source 1 passes[1 2 3]
Enter the nodes through which source 2 passes[1 2]
Enter the nodes through which source 3 passes[2 3]
Warning: Trust-region-reflective method does not currently solve this type of problem,
 using active-set (line search) instead.
> In fmincon at 437
  In Project at 61
Optimization terminated: first-order optimality measure less
 than options.TolFun and maximum constraint violation is less
 than options.TolCon.
No active inequalities.

x1 =

  1.0e+006 *

   -1.9107 1.1359 1.1359


fval =

 -42.3488 - 3.1416i

Why am I getting this? How can i modify this code in order for optimization to work properly?

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us