Is this the correct way to calculate a rotation matrix for a given angle around a unit vector, i am having problems verifying it.
function R = rot(k,fi)
% This is just to make it easier to read!
x = k(1);
y = k(2);
z = k(3);
% Create a 3x3 zero matrix
R = zeros(3,3);
% We use the formula for rotating a matrix about a unit vector k
R(1,1) = cos(fi)+x^2*(1-cos(fi));
R(1,2) = x*y*(1-cos(fi))-z*sin(fi);
R(1,3) = x*y*(1-cos(fi))+y*sin(fi);
R(2,1) = y*x*(1-cos(fi))+z*sin(fi);
R(2,2) = cos(fi)+y^2*(1-cos(fi));
R(2,3) = y*z*(1-cos(fi))-x*sin(fi);
R(3,1) = z*x*(1-cos(fi))-y*sin(fi);
R(3,2) = z*y*(1-cos(fi))+x*sin(fi);
R(3,3) = cos(fi)+z^2*(1-cos(fi));
end
I am using this algorithm

If you change the R(1,3) line to
and plug the above code into Matlab, then one way to see that the code is behaving as it should be, is to run
which gives the matrix
and this is what one would expect, since rotating 180 degrees around the $x$-axis corresponds to negating the $y$ and $z$-coordinates.