Path: news.mathworks.com!not-for-mail
From: "arnold szilagyi" <john.doe.nospam@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: underdetermined linear equation system
Date: Sun, 11 Oct 2009 19:05:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 52
Message-ID: <hata91$ra1$1@fred.mathworks.com>
References: <hasu5b$di4$1@fred.mathworks.com> <hasvc7$sbm$1@fred.mathworks.com>
Reply-To: "arnold szilagyi" <john.doe.nospam@mathworks.com>
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 1255287905 27969 172.30.248.37 (11 Oct 2009 19:05:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 11 Oct 2009 19:05:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1134066
Xref: news.mathworks.com comp.soft-sys.matlab:576546


thank you for your quick and precious reply.

first of all I tried the quadprog function with the min J(x) := |x|^2 cost function.
but all that matlab gives to me is zeros. 
here is the code that doesn't work for me (maybe I'm missing something):

A=[0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0;0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1;1 0 0 1 1 1 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0;0 0 1 0 0 0 1 1 1 1 0 1 0 0 0 1 0 0 0 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 1 0 1 0 1 1 0 0 1 1 1 0 0 0;1 1 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 0 1 1 0 0 0 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 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0]; 

B=[312;351;396;506;930;580;891;621;585;360;84;575;496;756;288];

n=51;
H=toeplitz([1 zeros(1,n-2)],[1 zeros(1,n-2)]);

f=zeros(50,1);

lb=zeros(50,1);

ub=ones(3,1);
ub=ub*100;

[x,fval,exitflag,output,lambda] = quadprog(H,f,A,B,[],[],lb,ub)


this is the situation: I look for 50 numbers which's average satisfies some constraints.
for example:
(a1+a2+a4)/3=20
(a1+a3)/2=60

so I made the A matrix corresponding to the groups of numbers and I made B in this way (adapted to my little example):

A=[1 1 0 1; 1 0 1 0];
B=[20*3; 60*2];

I made a diagonal matrix for H with the values of 1 on the diagonal, and put 0 to the f, because I just use the x^2 in the cost function.
I added lower and upper limits and called the function.
the answer is 50 zero.
I don't know what am I missing.


after this I tried the linprog function
every matrix is the same and I call

[x,fval,exitflag,output,lambda] = linprog(f,A,B,[],[],lb,ub)

now it gives me nice numbers as a solution. but they don't satisfy the average conditions. 
Maybe made a mistake to give to F zeros. but I don't know what should I try.

any suggestions?

regards
arnold