Professional Documents
Culture Documents
Miscellaneous Matlab Code Snippets SVD IMAGE COMPRESSION/WATERMARKING
Miscellaneous Matlab Code Snippets SVD IMAGE COMPRESSION/WATERMARKING
IMAGE COMPRESSION
MATRIX OPRRATIONS
%%
A= randi([0 9],3,1) * randi([0 9],1,3)
%%
%Create a 3x4 matrix with rank 3
A = randi (10,3, 3) ;
A =[A A*randi (5,3,1) 1;
rank (A)
%%
% Create a 3x3 matrix with rank 2
Office on the web Frame
A = randi (10, 3,2);
A =[A Atrandi (4,2, 1) 1;
rank (A)
%%
A=11 2 3 4;2 3 4 5];
b=[4;6];
Xp=pinv(A)*b; % check A*Xp—b
Nsv=null(A);
Nc=size(Nsv,2); % number of column vectors
Xn=Nsv*randi([0 9],Nc, 1);
X=Xp+Xn
%%
% Create a 3x2 matrix A with random integers between 1 and 10
A = randi(10, 3, 2);
% Display matrix A
disp('Matrix A:');
disp(A);
% Calculate rank of A
fprintf('Rank of A: %d\n', rank(A));
%%
% office on the web Frame random 5x4 matrix A with rank 2 and a 5x1 vector b such that Ax=b has infinite
solution.
A = randi (10, 5, 2) ;
A = [A A*randi (4,2,2)]; %creation of A matrix with rank 2
rank (A)
b = sum (A, 2); ° b is in column space of A
for i = 1:3
x = pinv (A) *b+null (A) *randi (4,2, 1); & solution
A*x : checking
x1 = 1x1 x]; % infinite solution
end
%% Using SVD find basis set for all the spaces associated with a matrix
A = randi(10, 4, 2);
A = [A A*randi(4, 2, 2)]; % Creation of A matrix with rank 2
r = rank(A);
[U, S, V] = svd(A);
Cs = U(:, 1:r); % Column space basis
disp('Rank of [A Cs]:');
disp(rank([A Cs]));
v = V';
Rs = v(:, 1:r); % Row space basis
disp('Rank of [A;Rs]:');
disp(rank([A; Rs]));
%%
while true
A = randi([-10, 10], 6);
if rank(A) == 3
break;
end
end
% SVD
[U, S, V] = svd(A);
disp('Singular Values:');
disp(diag(S));
disp('Matrix B:');
disp(B);
disp('Matrix C:');
disp(C);
eigenvalues_B = eig(B);
eigenvalues_C = eig(C);
disp('Eigenvalues of B:');
disp(eigenvalues_B');
disp('Eigenvalues of C:');
disp(eigenvalues_C');
%%
x=-50: 50;y=x;
[x1,x2]=meshgrid(x,y);
Z=(x1-3).^2+(x2-5).^2;
surfc(x,y,Z);
shading interp
Xlabel('x');
ylabel('y');
zlabel('z');