skew symmetric matrix from vector in matlab

To create a skew-symmetric matrix from a given vector v in MATLAB, you can use the following code:

main.m
n = length(v);
M = zeros(n,n);
for i = 1:n
    for j = 1:n
        M(i,j) = v(i)*v(j) - v(j)*v(i);
    end
end
111 chars
8 lines

This code initializes a zero matrix of size n by n, where n is the length of the vector v. It then fills in the matrix using the formula for a skew-symmetric matrix, which is:

main.m
M(i,j) = v(i)*v(j) - v(j)*v(i)
31 chars
2 lines

This creates a skew-symmetric matrix where the elements on the diagonal are zero, and the elements above the diagonal are the negative of those below the diagonal.

gistlibby LogSnag