November 19, 2019

MATLAB Matrices and Arrays

Matrices/Arrays in MATLAB

M = [1 2 3; 4 5 6; 7 8 9]
B=0:10:99
Z = zeros(5, 1)
zeros(3, 4)
A = ones(3,4)
O = ones(3)
M = magic(4)

B = rand(3, 5, 3) % random variables
randi([0,2], 3, 4) % random integers
randn(1, 7) % normal random variables
eye(6)
diag([-1, 2, 3])
toeplitz()
vander()
sin(M)
hlib()

A(4, 1)
A(8)
A(1:4, 3)
B(2, :)
M([2,3], 2)
C(2:5, 3)
A(3, 4) = 99

A' % transpose a matrix
P = a * inv(M)
A .* A
M .^ 3
A = [a, d] % concatenate horizontally, should have same number of rows
B = [b; c] % concatenate vertically, should have same number of columns
length(U) % maximum number of columns/rows
size(matrix33) % number of rows & columns
max(A)
[maxB, location] = max(B)
mean(R)

sin(A)
det(A)
eig(B)
[V, D] = eig(A)
eig(B, A)
[V, D, W] = eig(A, B)
norm(A*V - V*D)
norm(A*V - V*D, 1)
norm(A*V - V*D, 2)
norm(A*V - V*D, Inf)


Related Articles:   Matrix Operations and Vectors in Octave


No comments:

Post a Comment