gpt4 book ai didi

matlab - Matlab : numerical arguments or counterexample? 中线性不等式/等式系统隐含的不等式

转载 作者:太空宇宙 更新时间:2023-11-03 19:28:42 26 4
gpt4 key购买 nike

我有一个线性不等式/等式系统要在 Matlab 中求解,我使用 linprog .由于一些不等式很严格,我使用了一个非常小的常数 eps按照说明获得严格包含 here

函数solve下面在为 eps 提供值后求解系统.

function pj=solve(eps)

%Inequalities
%x(1)-x(5)-x(9)-x(10)-x(11)-x(15)-x(16)-x(17)-x(19)<=0;
%x(2)-x(6)-x(9)-x(12)-x(13)-x(15)-x(17)-x(18)-x(19)<=0;
%x(3)-x(7)-x(10)-x(12)-x(14)-x(16)-x(17)-x(18)-x(19)<=0;
%x(4)-x(8)-x(11)-x(13)-x(14)-x(15)-x(16)-x(18)-x(19)<=0;

%x(1)+x(2)-x(5)-x(9)-x(10)-x(11)-x(15)-x(16)-x(17)-x(19)-...
% x(6)-x(12)-x(13)-x(18)<=0;
%x(1)+x(3)-x(5)-x(9)-x(10)-x(11)-x(15)-x(16)-x(17)-x(19)-...
% x(7)-x(12)-x(14)-x(18)<=0;
%x(1)+x(4)-x(5)-x(9)-x(10)-x(11)-x(15)-x(16)-x(17)-x(19)-...
% x(8)-x(13)-x(14)-x(18)<=0;
%x(2)+x(3)-x(6)-x(9)-x(12)-x(13)-x(15)-x(17)-x(18)-x(19)-...
% x(7)-x(10)-x(14)-x(16)<=0;
%x(2)+x(4)-x(6)-x(9)-x(12)-x(13)-x(15)-x(17)-x(18)-x(19)-...
% x(8)-x(11)-x(14)-x(16)<=0;
%x(3)+x(4)-x(7)-x(10)-x(12)-x(14)-x(16)-x(17)-x(18)-x(19)-...
% x(8)-x(11)-x(13)-x(15)<=0;


%x(1)+x(2)+x(3)-x(5)-x(9)-x(10)-x(11)-x(15)-x(16)-x(17)-x(19)-...
% x(6)-x(12)-x(13)-x(18)-...
% x(7)-x(14)<=0;
%x(1)+x(2)+x(4)-x(5)-x(9)-x(10)-x(11)-x(15)-x(16)-x(17)-x(19)-...
% x(6)-x(12)-x(13)-x(18)-...
% x(8)-x(14)<=0;
%x(1)+x(3)+x(4)-x(5)-x(9)-x(10)-x(11)-x(15)-x(16)-x(17)-x(19)-...
% x(7)-x(12)-x(14)-x(18)-...
% x(8)-x(13)<=0;
%x(2)+x(3)+x(4)-x(6)-x(9)-x(12)-x(13)-x(15)-x(17)-x(18)-x(19)-...
% x(7)-x(10)-x(14)-x(16)-...
% x(8)-x(11)<=0;


%Equalities
%x(1)+x(2)+x(3)+x(4)=1;
%x(5)+x(6)+x(7)+x(8)+x(9)+x(10)+x(11)+x(12)+x(13)+x(14)+x(15)+x(16)+x(17)+x(18)+x(19)=1;


%I also want each component of x to be different from 1 and 0 (strictly included between 1 and 0 given the equalities constraints)
%x(1)>0 ---> x(1)>=eps ---> -x(1)<=-eps
%...
%x(19)>0
%x(1)<1 ---> x(1)<=1-eps
%...
%x(19)<1

%52 inequalities (14+19+19)
%2 equalities
%19 unknowns

A=[1 0 0 0 -1 0 0 0 -1 -1 -1 0 0 0 -1 -1 -1 0 -1;...
0 1 0 0 0 -1 0 0 -1 0 0 -1 -1 0 -1 0 -1 -1 -1;...
0 0 1 0 0 0 -1 0 0 -1 0 -1 0 -1 0 -1 -1 -1 -1;...
0 0 0 1 0 0 0 -1 0 0 -1 0 -1 -1 -1 -1 0 -1 -1;...

1 1 0 0 -1 -1 0 0 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1;...
1 0 1 0 -1 0 -1 0 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1;...
1 0 0 1 -1 0 0 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1;...
0 1 1 0 0 -1 -1 0 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1;...
0 1 0 1 0 -1 0 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1;...
0 0 1 1 0 0 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1;...

1 1 1 0 -1 -1 -1 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0;...
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;...
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0;...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0;...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0;...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]; %52x19

b=[zeros(1,14) -eps*ones(1,19) (1-eps)*ones(1,19)]; %1x52

Aeq=[1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]; %2x19
beq=[1 1]; %1x2

f=zeros(1,19); %1x19

x=linprog(f,A,b,Aeq,beq);

if ~isempty(x)
pj=x;
else
pj=NaN;


end

我相信(但我不知道如何分析显示)是我放入 linprogr 中的不等式/等式函数内部的算法 solve是这样的,即 Matlab 产生的解决方案将满足另一个不等式,如下所示:

clear
rng default

%solve system
p1=solve(unifrnd(0,0.05));

%solve system
p2=solve(unifrnd(0,0.05));


%solve system
p3=solve(unifrnd(0,0.05));



if ~isnan(p1) & ~isnan(p2) & ~isnan(p3) %#ok<AND2>

%LHS
lhs=(p1(2)+p1(3)+p1(4))*1*1+...
p1(1)*(p2(1)+p2(4))*1+...
p1(1)*p2(2)*(p3(2)+p3(3)+p3(4))+...
p1(1)*p2(3)*(p3(1)+p3(2)+p3(3));


%RHS
rhs=(1-(p1(5)+p1(9)+p1(10)+p1(11)+p1(15)+p1(16)+p1(17)+p1(19)))*...
1*...
1+...
... +
(p1(5)+p1(9)+p1(10)+p1(11)+p1(15)+p1(16)+p1(17)+p1(19))*...
(p2(5)+p2(8)+p2(11))*...
1+...
... +
(p1(5)+p1(9)+p1(10)+p1(11)+p1(15)+p1(16)+p1(17)+p1(19))*...
(p2(7)+p2(10)+p2(14)+p2(16))*...
((p3(5)+p3(9)+p3(10)+p3(17))+(p3(6)+p3(7)+p3(12)))+...
... +
(p1(5)+p1(9)+p1(10)+p1(11)+p1(15)+p1(16)+p1(17)+p1(19))*...
(p2(6)+p2(9)+p2(13)+p2(15))*...
((p3(8)+p3(13)+p3(14)+p3(18))+(p3(6)+p3(7)+p3(12)))+...
... +
(p1(5)+p1(9)+p1(10)+p1(11)+p1(15)+p1(16)+p1(17)+p1(19))*...
(p2(12)+p2(17)+p2(19))*...
(p3(6)+p3(7)+p3(12));

check=(lhs>=rhs); %I expect check to be 1
else
end

我相信解决方案p1,p2,p3将交付check=1 .

问题:如前所述,我不知道如何解析显示;有没有办法产生令人满意的数值论证?或者,你能不能扼杀我的信仰并提供解决方案p1,p2,p3送货 check=0

最佳答案

你可以做的是将问题从 19 个参数扩展到 3x19 = 57 个参数,编写一个计算 lhs 和 rhs 之间差异的函数,并尝试在给定约束条件下最小化该函数。如果低于零,则表示 rhs > lhs。扩展约束:

ACell = repmat({A}, 1, 3); % diagonal matrix with A repeated 3 times on diagonal
A = blkdiag(ACell{:}); % 156x57
b = [b b b]; % 1x156
AeqCell = repmat({Aeq}, 1, 3);
Aeq = blkdiag(AeqCell{:}); % 6x57
beq = [beq beq beq]; % 1x6

计算误差的函数:

function error = errorFun( p )

p1 = p(1:19);
p2 = p(20:38);
p3 = p(39:57);

if ~isnan(p1) & ~isnan(p2) & ~isnan(p3) %#ok<AND2>

lhs= (...);
rhs= (...);
error= lhs - rhs;

else
error= 1;
end
end

现在您可以使用一些优化工具来找到最小的 errorFun,例如 fmincon :

x = fmincon(@errorFun, zeros(57, 1), A, b, Aeq, beq, [], [], [], options);

我找到的解决方案是肯定的,这意味着您的假设应该是正确的。

关于matlab - Matlab : numerical arguments or counterexample? 中线性不等式/等式系统隐含的不等式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46939502/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com