|
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
**************
|