MATLAB: Wrong output when using random numbers

matrix manipulationrandom number generator

I'm attempting to satisfy an equation using 10 random numbers in the range [-pi,pi]. The results tend to be in an odd format and only one of the values ever seems to match, suggesting that something is going wrong. My attempt is below, any help would be apprectiated :).
x = (rand(10,1) * 2 - 1) * pi
y1 = (3*cot(x)-(cot(x).^3))/(1 - 3*(cot(x).^2))
y2 = cot(3*x)
y1 =
Columns 1 through 7
0 0 0.0047 0 0 0 0
0 0 -0.0395 0 0 0 0
0 0 -2.6571 0 0 0 0
0 0 0.0034 0 0 0 0
0 0 0.0047 0 0 0 0
0 0 0.0082 0 0 0 0
0 0 -0.0068 0 0 0 0
0 0 0.0095 0 0 0 0
0 0 -0.0573 0 0 0 0
0 0 0.1041 0 0 0 0
Columns 8 through 10
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
y2 =
-1.4220
-0.4570
-2.6571
-0.8258
-1.4221
0.4081
-0.2741
0.7070
-0.5596
0.7511
Granted the values change each time, it seems that one always seems to work and I'm not entirely sure why.

Best Answer

./ % this is why? see Array vs. Matlab operations [Google it]