Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- clear all
- close all
- A = [ 2 1; 3 3 ; 2 0 ; 1 0 ; 0 1 ];
- B = [10 ; 24 ; 8 ; 0 ; 0 ];
- Z = [ -1 ; -1 ; -1 ; 1 ; 1 ];
- F = [300 200];
- [w, k] = size(A);
- tmp = 1;
- for i = 1:w-1
- AT(1,:) = A(i,:);
- BT(1,:) = B(i,:);
- for j = i+1:w
- AT(2,:) = A(j,:);
- BT(2,:) = B(j,:);
- R = inv(AT) * BT;
- %R = AT \ BT;
- if (~isinf(R))
- if (~isnan(R))
- M(tmp, :) = R;
- tmp = tmp + 1;
- end
- end
- end
- end
- disp('punkty przeciecia');
- disp(M)
- [w1, k1] = size(M);
- punkty = 0;
- tmp1 = 1;
- for i = 1:w1
- for j = 1:w
- wynik = A(j, 1) * M(i, 1)+ A(j, 2) * M(i, 2);
- if Z(j) == -1
- if wynik <= B(j)
- punkty = punkty + 1;
- end
- else
- if wynik >= B(j)
- punkty = punkty + 1;
- end
- end
- end
- if punkty > w-1
- punktyDopuszczalne(tmp1, :) = M(i, :);
- tmp1 = tmp1 + 1;
- end
- punkty = 0;
- end
- disp('punkty dopuszczalne RD');
- disp(punktyDopuszczalne);
- [w2, k2] = size(punktyDopuszczalne);
- maxWartosc = 0;
- for i=1:w2
- tmp2 = F(1).*punktyDopuszczalne(i, 1) + F(2).*punktyDopuszczalne(i, 2);
- if tmp2 > maxWartosc
- maxWartosc = tmp2;
- end
- end
- disp('max wartosc: ');
- disp(maxWartosc);
- X = min(M(1)):0.001:max(M(2));
- hold on
- for i=1:5
- Y = (B(i) - A(i, 1) * X) / A(i, 2);
- plot(X, Y);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement