Advertisement
Guest User

Untitled

a guest
May 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. clc
  2. clear all
  3. close all
  4. A=[2,1;
  5. 3,3;
  6. 2,0;
  7. 1,0;
  8. 0,1];
  9. B=[ 10;
  10. 24;
  11. 8;
  12. 0;
  13. 0];
  14. Z=[-1;-1;-1;1;1];
  15. F= [ 300,200];
  16. %2x+1y<=10;
  17. %3x+3y<=24;
  18. %2x+0y<=8;
  19. %F= 300*x+200*y = MAX;
  20. m=length(B);
  21. k=1;
  22. for i=1:m-1
  23. AT(1,:)=A(i,:);
  24. BT(1,1)=B(i,:);
  25. for j=i+1:m
  26. AT(2,:)=A(j,:);
  27. BT(2,1)=B(j,:);
  28.  
  29.  
  30. R=AT\BT;
  31. if(sum(isnan(R))+sum(isinf(R)))==0
  32. T(k,:)=R';
  33. k=k+1;
  34. end
  35. T
  36. end
  37. end
  38.  
  39. te=0;
  40. kk=0;
  41. f=0;
  42. n=1;
  43. for i=1:size(T,1)
  44. f=0;
  45. for j=1:5
  46. if Z(j)==-1
  47. if A(j,1)*T(i,1)+A(j,2)*T(i,2)<=B(j)
  48. f=f+1;
  49. end
  50. end
  51. if Z(j)==0
  52. if A(j,1)*T(i,1)+A(j,2)*T(i,2)==B(j)
  53. f=f+1;
  54. end
  55. end
  56. if Z(j)==1
  57. if A(j,1)*T(i,1)+A(j,2)*T(i,2)>=B(j)
  58. f=f+1;
  59. end
  60. end
  61. end
  62. if f==5
  63. T1(n,:)=T(i,:);
  64. n=n+1;
  65. end
  66. end
  67.  
  68. T1
  69. hold on
  70. x=min(T(:,1))-1:0.01:max(T(:,2))+1;
  71. for i=1:f
  72. if A(i,2) ~= 0
  73. y=(B(i)-A(i,1)*x)/A(i,2);
  74. plot(x,y)
  75. else
  76. y=(B(i))/A(i,1)*ones(length(x),1);
  77. plot(y,x)
  78. end
  79. end
  80.  
  81. temp1=convhull(T1(:,1),T1(:,2));
  82. fill(T1(temp1,1),T1(temp1,2),'r');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement