����������� ���������� �� ��� ������� �� ������� �������� �� ���������� ��������� ������� ��������� �������� 2:
8.� ������������� ������� ��� ������ �������.
�� ���� �������� �� ������ ����������� �� �������� ��� �������� �������� �� ������ ������� �� �������� �� ������������ ������������ ��� ������������� �� �� ���� �������������� �������������� ��������� z
=cx
��� �������� � ��� ��������� �� �������� x � ������ �� A x
= b�
x ≥ 0
������
a11 a x1 21 x = � A = ... x2 am1
a22 � ... am 2 a12
c = [ c1
b1 b 2 c2 ] b = ... bm
��������
A ������������ ��������� �� ������ ��������� ������� ���� ����� ������ �� �������� �������� �� ������������� � �������� ��� ������� ��� �� ���� ���������. function simplex_graphic(A,b,c,direccion) function %Método Simplex gráfico para resolver el problema de maximizar z=c*x sujeta %a A*x<=b % %Donde: %- A = Matriz de la parte A del sistema de restricciones: % * A=[a11,a12,...,a1n;a21,a22 ,...,a2n;am1,am2,...,amn] %- b = Vector columna de la parte b del sistema de restricciones: % * b=[b1;b2;...;bm] % %- c = Vector de la parte c del sistema del problema a resolver: % * c=[c1,c2,...,cn] %- direccion = Vector columnna de las igualdades o desigualdades del sistema % de restricciones: % * direccion=['==';'<=';'~='; '<'] (Por ejemplo) % %Da como resultado una grafica donde se muestran las soluciones posibles
%soluciones de una a una haciendo clic en la tecla 1 para que así el %usuario pueda elejir la que mas le convenga. [m,n]=size(A); if n~=2 string='El problema es solo para dos variables'; mfgbox(string,'ErrorWindow','Help'); return end A=[A, eye(m)]; n=n+m; vertices=corner1(A,b); if length(vertices)==0 error('No existe region factible'); end vertices=vertices(1:2,:); vertices=deleteCol1(vertices); d=corner1([A;ones(1,n)],[zeros(m,1);1]); if length(d)>0 error('Noexiste region factible acotada'); end x1=vertices(1,:); x2=vertices(2,:); k=convhull(x1,x2); hold on; fill(x1(k),x2(k),[0.7 0.7 0.7]); xlabel('x_1','FontSize',15); ylabel('x_2','FontSize',15); z=c*vertices; z0=max(z); [~,nvert]=size(vertices); %xmax=max(vertices(1,:)); xmin=min(vertices(1,:)); for j=1:nvert clc; x0=vertices(1,j); y0=vertices(2,j); if c(1)*c(2)~=0 x=[0.7*x0,1.3*x0]; y=y0+(-c(1)/c(2))*(x-x0); plot(x,y,'r--','LineWidth',2); end title(['Región de solución factible, con z=',num2str(z0)],'FontSize',15) text(x0,y0,[' (',num2str(x0),',',num2str(y0),')'],'Fontsize',15) plot(x0,y0,'o',... 'MarkerEdgeColor','k',... 'MarkerFaceColor','r',... 'MarkerSize',5) grid on respuesta=input('\n-Presione la tecla 1 para mostrar el siguiente vertice\n-Presione la tecla 0 para salir\n(De lo contrario dará error)\nRespuesta: '); switch(respuesta); case 1 case 0 break end
end display('Se ha alcanzado el numero máximo de posibles soluciones (elija uno)') display('Se recomienda la que coincida con la sol factible mostrada al evaluar') end
�� �������� ������ �������� �� ���� ��������� �������� ��� ������ ����� ������ �� ��, ��� ��� ��� ����������: function puntos=corner1(A,b) %Puntos extremos [m,n]=size(A); puntos=[]; if n>=m combin=nchoosek(n,m); %Coeficientes binomiales v=nchoosek(1:n,m); for k=1:combin y=zeros(n,1); x=inv(A(:,v(k,:)))*b; if all(x>=0 & (x~=inf & x~=-inf)) y(v(k,:))=x; puntos=[puntos y]; end end else error('Número de ecuaciones es > número de variables'); end puntos puntos=deleteCol1(puntos); end
� function puntos=deleteCol1(puntos) %Borra columnas repetidas [nn,L]=size(puntos); v=[]; for i=1:L-1 for j=i+1:L x=puntos(:,i); y=puntos(:,j); if all(x==y) v=[v,j]; end end end puntos(:,v)=[]; end
���� �� �������� ������� ����� �� ����� (������), ����� ����� �� ������� ��� ��� ����������: >> A=[7 11;10 8;1 0;0 1] A = 7
11
10
8
1
0
0
1
>> b=[77;80;9;6] b = 77 80 9 6 >> c=[150 175] c = 150
175
>> direccion=['<=';'<=';'<=';'<='] direccion = <= <= <= <=
�� ���� ������ �� ��������� ��� ������ �� �� ������������� �������:
�� �������� �� �������� �������� �� ������������ ��� �������� ��� �������� ����� ��� ��� ����������� ��� ����� � ����������� �� ������ ������� ���� ��� �� ������� ��������� ���� �� �� ������ �������� ��� ������ ���������� �� �, ��� ��� �� �� �������� ������������� �� ����� �� � �� ������ �����������, ���������� �� ��� �� ��� ������ ������������� ���������.
�� ����� ������ ��� �� ��������� ��������.
������� ��������: ��� ������� �� ����������� ��������� � ���������� ��� ������, ������� 3 �������� �� �� ����������: ����������, ����������� � �������, ���� ������� �������� 72, 50 � 40 ����� ���������������, �������� ��� ���������� �������� �������� 3 ����� �� ����������, 1 ���� �� ����������� � 1.5 ����� �� �������, �� ���������� ��������� �� ������ �������� �� 1 ���� �� ����������, 2 ����� �� ����������� � ��� �� �������. �� �� �������� ��� ������� ��� ���������� �������� �� �� $50 � ��� ��������� �� ������ �� �� $80. �C������ ����������� ���� �������� �� ������� ���� ������� �� ������ ��������? ������� C��������� C���������� ������� ��������
(�1) �������� 3 1 1.5 $50
(�2) C�������� 1 2 1 $80
������� �������� �=50�1 + 80�2 ������������� 3�1 + �2 ≤ 72 �1 + 2�2 ≤ 50 1.5 �1 + �2 ≤ 40 A����� �1 ≤0 � �2 ≤0 ���� � �� ����� �� ����� ���������� ������� 3000 3000 = 50�1 + 80�2 ������������� ��� ����� �� �������: >> A A = 3.0000
1.0000
����� ����������� 72 50 40
1.0000
2.0000
1.5000
1.0000
>> b b = 72 50 40 >> c c = 50
80
�� ���� ������ �� ��������� ��� ������ �� �� ������������� �������:
C����������� �� ���� � �� ����� �� �� �����, �� ������ ��������� �� ���� �������� �� ��������� �� ������������ ������������� ������ � ��� �� ���������� �� ��� �� ��������� �� �� ����� �� ������ ������� �� �������� ������������� � ���� ������������ �� ���� �� ������ �������, ���� �� ��������� �� �� ����������� ��� ��������. C��� ��������� ��� ��� ������ �������� ��������� � ������ �� �������� � ��������� ��� ������, ��� ���� �� ������ ���� �� ���� �� ������� ������������ ���� ��� �� ������� � ��� ���������� ��� �������� � �� ���� ������� ������������������.
C����������: �������� �� ������������ ����� �� ������ �� ������� ��������� � ������ ��� ��� ��� ����� �� �� ��������� �� ������� �� ������ ��������� ���� ������� ��� ��� ������������ ��� ��������, �� ����� ����� �� �� ����� �� ��� �� ���� �� ������ ��� ��������� �� �� �������� 8 �� ������ ����������� �� �������� ��� �������� �������� �� ������ �������� � �