Advertisement
Guest User

Untitled

a guest
May 28th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. clc
  2. clear all
  3. close all
  4.  
  5. A = [ 2 1; 3 3 ; 2 0 ; 1 0 ; 0 1 ];
  6. B = [10 ; 24 ; 8 ; 0 ; 0 ];
  7. Z = [ -1 ; -1 ; -1 ; 1 ; 1 ];
  8. F = [300 200];
  9.  
  10. [w, k] = size(A);
  11. tmp = 1;
  12. for i = 1:w-1
  13. AT(1,:) = A(i,:);
  14. BT(1,:) = B(i,:);
  15. for j = i+1:w
  16. AT(2,:) = A(j,:);
  17. BT(2,:) = B(j,:);
  18. R = inv(AT) * BT;
  19. %R = AT \ BT;
  20. if (~isinf(R))
  21. if (~isnan(R))
  22. M(tmp, :) = R;
  23. tmp = tmp + 1;
  24. end
  25. end
  26. end
  27. end
  28. disp('punkty przeciecia');
  29. disp(M)
  30.  
  31. [w1, k1] = size(M);
  32. punkty = 0;
  33. tmp1 = 1;
  34.  
  35. for i = 1:w1
  36. for j = 1:w
  37. wynik = A(j, 1) * M(i, 1)+ A(j, 2) * M(i, 2);
  38.  
  39. if Z(j) == -1
  40. if wynik <= B(j)
  41. punkty = punkty + 1;
  42. end
  43. else
  44. if wynik >= B(j)
  45. punkty = punkty + 1;
  46. end
  47. end
  48. end
  49. if punkty > w-1
  50. punktyDopuszczalne(tmp1, :) = M(i, :);
  51. tmp1 = tmp1 + 1;
  52. end
  53. punkty = 0;
  54. end
  55.  
  56. disp('punkty dopuszczalne RD');
  57. disp(punktyDopuszczalne);
  58.  
  59. [w2, k2] = size(punktyDopuszczalne);
  60. maxWartosc = 0;
  61. for i=1:w2
  62. tmp2 = F(1).*punktyDopuszczalne(i, 1) + F(2).*punktyDopuszczalne(i, 2);
  63. if tmp2 > maxWartosc
  64. maxWartosc = tmp2;
  65. end
  66. end
  67.  
  68. disp('max wartosc: ');
  69. disp(maxWartosc);
  70.  
  71. X = min(M(1)):0.001:max(M(2));
  72. hold on
  73. for i=1:5
  74. Y = (B(i) - A(i, 1) * X) / A(i, 2);
  75. plot(X, Y);
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement