meedshit

s2p2d - Optilab

May 16th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. clear; clc; close all;
  2.  
  3. % Dimension of A and b
  4. n = 2;
  5.  
  6. % Generate all vectors x of dimension d with coordinates between -range and +range
  7. step = 1;
  8. range = 20;
  9. interval = -range:step:range; % the window of x to be observed regarding the set 'C'
  10.  
  11. % Generate all combinations in the defined range
  12. x = combn(interval, n); x = x';
  13.  
  14. % your solution here
  15.  
  16. A = diag([-2 -3]); % A is Negative semi-definite
  17. b = zeros(2,1);
  18. c1 = -sqrt(2);
  19. c2 = 100;
  20.  
  21. eig_A = eig(A);
  22. eig_A(eig_A >= 0);
  23. if numel(eig_A(eig_A >= 0)) == n
  24. disp('A is Positive semi-definite')
  25. elseif numel(eig_A(eig_A <= 0)) == n
  26. disp('A is Negative semi-definite')
  27. else
  28. disp('A is neither Positive nor Negative semi-definite')
  29. end
  30.  
  31.  
  32. % Plot the set C using the sign function
  33. % the points inside the set 'C' should get the value (+1) and the points outside the set should get the value (-1).
  34.  
  35. Q = diag(x'*A*x) + (b'*x)'+ c1*ones(size(x,2),1);
  36. Q_sign = -1*sign(Q);
  37.  
  38.  
  39. figure();
  40.  
  41. surf(interval, interval, reshape(Q, [41, 41]));
  42. title('c = -sqrt(2)');
  43.  
  44.  
  45.  
  46. Q = diag(x'*A*x) + (b'*x)'+ c2*ones(size(x,2),1);
  47. Q_sign = -1*sign(Q);
  48.  
  49.  
  50. figure();
  51. surf(interval, interval, reshape(Q, [41, 41]));
  52. title('c = 100');
Add Comment
Please, Sign In to add comment