==================================== ===== Matlab - Dialog window ===== ==================================== Try these commands in Matlab and see, what they are doing: a = 5 b = 6; % semicolon inhibits Matlab output b % shows the value of the variable b c = (a+b)*3/(20-a) sqrt(5-3*i) % square root can be computed from a complex number, too a=sqrt(2) + sin(c+1); help sin ========= arrays - vectors ============= y = [ 2 0 1 -2 -3 4 1 ]; y(3) % the third element of the vector y y(3) = 7; % changing just the third element of y y' % transposition of the vector x = -1:4 x = 2 : 0.5 : 5; format rat x format x help format c = pi : 0.5 : 2*pi; ---- the difference y-x of vectors (of the same size) --------- size(x) size(y) d = y-x ---- the maximal element of the vector d (absolute value of it) --------- max(abs(d)) ------ function of the vector element by element ----- y = x.*exp(x)+x.^2; ========== graphs ============== plot(x, y) plot(x,y, 'r') plot(x,y, 'go') plot(x,y, 'r*') help plot % parametric curve: t = 0 : 0.2 : 2*pi; x = sin(t); y = cos(t); plot(x, y) axis equal axis normal =========== 2D arrays - matrices ================ A = [ 1 2 3; 4 5 6]; size(A) % number of rows, number of columns A(2,3) % the element at 2. row and 3. column A(2,:) % the second row A(:,3) % the third column --- adding the matrices: B = [ 0 -2 1; 1 0 1]; C = A + B; Z = 0.3 * A --- multiplying the matrices: X = A*A' Y = [1 2; -3 2] * A --- solution of the system of the equations (with regular matrix): A = [ 3 2 1; 0 2 0; 3 6 7]; b = [ 11; 2; 33]; % or b = [ 11 2 33]'; x = A \ b --- function of a matrix as an entity -------- B = A^2 % notice the difference from B = A.^2 det(A) % determinant inv(A) % matrix inversion % eigenvalues eig(A) [U, D]=eig(A) % eigenvalues and eigenvectors % check the matrix equation A*U - D*U = 0 : A*U - D*U % for k = 1, 2, 3 : k=1; U(:,k) % eigenvector D(k,k) % the corresponding eigenvalue % so it holds A*U(:,k)-D(k,k)*U(:,k) = 0 for k = 1,2,3 : k=1; A*U(:,k)-D(k,k)*U(:,k) ------ function of a matrix element by element ----- B = A.*A; C = A.^2; S = sin(A); =========== APPENDIX =============== =========== ezplot ============== ezplot('x*sin(x)') % in the interval < -2*pi, 2*pi > or: f = 'x*sin(x)'; ezplot(f) grid on ezplot(f, [-2, 10]) % in the interval < -2, 10 > % or ezplot(f, -2, 10) ==================== ezplot 2D ============ ezplot('x^2 + y^2 - 4') a = 9; ezplot(['x^2 + y^2 - ', int2str(a) ]) f = 'x^2 - y^2-5'; ezplot(f, [-10, 10]) % in a square ezplot(f, [-10, 10, -5, 5]) % in a rectangle % graphical solution of equations ezplot('x^2 + 1') % the first function hold on % plotting into the same graph ezplot('x^2 + y^2 - 4') % the second function axis([-2 2 0 3]) % zoom in at the intersection ================================================