Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear; clc; close all;
- % Dimension of A and b
- n = 2;
- % Generate all vectors x of dimension d with coordinates between -range and +range
- step = 1;
- range = 20;
- interval = -range:step:range; % the window of x to be observed regarding the set 'C'
- % Generate all combinations in the defined range
- x = combn(interval, n); x = x';
- % your solution here
- A = diag([-2 -3]); % A is Negative semi-definite
- b = zeros(2,1);
- c1 = -sqrt(2);
- c2 = 100;
- eig_A = eig(A);
- eig_A(eig_A >= 0);
- if numel(eig_A(eig_A >= 0)) == n
- disp('A is Positive semi-definite')
- elseif numel(eig_A(eig_A <= 0)) == n
- disp('A is Negative semi-definite')
- else
- disp('A is neither Positive nor Negative semi-definite')
- end
- % Plot the set C using the sign function
- % the points inside the set 'C' should get the value (+1) and the points outside the set should get the value (-1).
- Q = diag(x'*A*x) + (b'*x)'+ c1*ones(size(x,2),1);
- Q_sign = -1*sign(Q);
- figure();
- surf(interval, interval, reshape(Q, [41, 41]));
- title('c = -sqrt(2)');
- Q = diag(x'*A*x) + (b'*x)'+ c2*ones(size(x,2),1);
- Q_sign = -1*sign(Q);
- figure();
- surf(interval, interval, reshape(Q, [41, 41]));
- title('c = 100');
Add Comment
Please, Sign In to add comment