Wrong output when using random numbers

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.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by