% CMSC 426 help help plus demo % Simple interpreted commands help ops 7+3 8-2 2^7 sqrt(17*3^2) x = 7; y = 8; x*y % Notice difference between: z = x*y; % and z % Making a vector x = [1 2 3 4] % or y = 1:4; % or y1 = [y,y] % Making a column vector z = [1; 2; 3; 4] % or z = x' % What happens when we do: [y, z] % Indexing into vectors x(2) x(2:3) x(2:4) % Adding vectors x + (3:6) % Scaling vectors 7*x % Vector operations sum(x) max(x) x.^2 y = x/(sqrt(sum(x.^2))) % Inner products theta1 = pi/4; theta2 = pi/8; u = [cos(theta1); sin(theta1)] v = [cos(theta2); sin(theta2)] u'*v cos(pi/8) % Matrices A = [1, 2, 3; 4, 5, 6] B = [1, 0, 1; 0, 1, 0] % Note [A,A] [B;[7, 6, 5]] A+B C = [7, 2; 3, 1] C*A A*C I = eye(2) C C*I D = [4, 0; 4, 5] A A' C C' det(C) C inv(C) inv(C)*C C*inv(C) % Indexing A A(2,1) A(2,1:2) A(2,:) % Geometric transformations % translation Q = [0, 0, 1, 1; 0, 1, 0, 1]; figure plot(Q(1,:), Q(2,:), 'o', 'LineWidth', 6) Q = [Q; ones(1,4)] T = [1, 0, -.5; 0, 1, 1] Qt = T*Q hold on plot(Qt(1,:), Qt(2,:), 'o', 'LineWidth', 6) hold off % rotation Q = [0, 0, 1, 1; 0, 1, 0, 1]; figure plot(Q(1,:), Q(2,:), 'o', 'LineWidth', 6) R = [cos(pi/4), -sin(pi/4); sin(pi/4), cos(pi/4)]; R*R' Qr = R*Q hold on plot(Qr(1,:), Qr(2,:), 'ok', 'LineWidth', 6) hold off T = rand(2,2) [r1, s, r2] = svd(T) T r1*s*r2 r1*r1' s % Files pwd ls path help addpath % Look at function test test(3,4) % Images dog = imread('dog1.jpg'); figure imshow(dog); dogbw = rgb2gray(dog); figure imshow(dogbw); imshow(imrotate(dogbw,45,'bilinear')); % iteration for i = 1:5 i, end % We can zoom in on the nose figure; imshow(dogbw(120:240, 150:270)) % Look at the raw pixel values. for i = 170:190, for j=200:220, fprintf(1,'%3.3d ', double(dogbw(i,j))); end, fprintf(1,'\n'); end dogbw(170:200,215)' % or plot them. figure plot(dogbw(170:200,215)) size(dog)