Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: help for constrained optimization  -using fmincon
Date: Thu, 17 Sep 2009 05:28:02 +0000 (UTC)
Organization: Indian Institute of Technology
Lines: 44
Message-ID: <h8shd2$sb6$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1253165282 29030 172.30.248.37 (17 Sep 2009 05:28:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 17 Sep 2009 05:28:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 223861
Xref: news.mathworks.com comp.soft-sys.matlab:570985


Hi 
I am trying to minimize a function (y) with linearity constraint. 
I was using the fmincon and I'm not getting desired results. Terminating message is coming.
So I also passed on gradient also. But now program is showing error. Can someone tell me where is the problem.

with regards,
murthy

******************
clear all
clc
global lk sk;
lk = [52,81,77,76,16,106,48,99,66,79];
sk = [0.39,0.56,1.03,0.47,0.93,1.20,1.74,1.86,1.23,0.54];
K = 10;
R = 350;
x0 = lk/4;
% f = @(x)parameterfun(x,sk,lk);
A = [];
b = [];
Aeq = ones(1,K);
beq = R;
lb = zeros(1,K);
ub = lk;
options = optimset('Algorithm','active-set');
options = optimset(options,'GradObj','on');
tic
[x,fval]=fmincon(@parameterfun,x0,A,b,Aeq,beq,lb,ub,[],options);
[x' rk']
toc
**********
function [y,g] = parameterfun(x)
global lk sk;
y = 0;
for i = 1:numel(x)
    y = y + sk(i)*exp(-2*pi/sk(i))*(exp(2*pi*x(i)/(lk(i)*sk(i)))-1);
end
if nargout  > 1
    g = 0;
    for i = 1:numel(x)
        g = g + 2*pi/lk(i)*exp(-2*pi/sk(i))*exp(2*pi*x(i)/(lk(i)*sk(i)));
    end
end
**************