# Matlab rotation matrix function not working correctly

I have made function in Matlab, that shale calculate the rotation matrix for fi degrees around unit vector k.

function R = rot(k,fi)

% This is just to make it easyer to read!
x = k(1);
y = k(2);
z = k(3);

% Create a 3x3 zero matrix
R = zeros(3,3);
% We use the formual for rotationg matrix about a unit vector k

end


But it don't seem to work, i have a test rules

rot(k,0) == I
rot(k,fi) == rot(k,fi+360)
rot(-k,fi) == transpose(rot(k,fi))
rot(k,f1)*rot(k,f2) == rot(k,f1+f2)
rot(k,fi)*k == k


My function is always successfull on rule nr 1, 3 and sometime on 2. What am i doing wrong here? is my function not correct?

-
How different are the results? Is it a case of rounding error? Also, $k$ must be a unit vector. – Daryl Oct 24 '12 at 21:13
If it's the test rot(k,fi) == rot(k,fi+360) that's failing, this is caused almost certainly by rounding errors -- you're only using the second argument as an argument for the sine and cosine, which should be invariant. One would expect rounding errors, though -- are these comparisons exact? If so, I'd be surprised if the test didn't fail. – joriki Oct 24 '12 at 21:24
The diffrence are small! example sometime are 0 compared with a -0 – DoomStone Oct 24 '12 at 22:17