Let say that I want to generate random numbers between 1-6 for output 5×6..each row will generate random number between 1-6..tq
MATLAB: Let say that I want to generate random numbers between 1-6 for output 5×6..each row will generate random number between 1-6..tq
let say that i want to generate random numbers between 1-6 for output 5x6..each row will generate random number between 1-6..tq
Related Solutions
X = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23];Y = [23,22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2];V = [6.630, 7.650, 8.030, 8.170, 8.370, 8.400, 8.400, 8.370, 8.360, 8.390, 8.280, 8.270, 8.280, 8.290, 8.220, 8.250, 8.160, 8.080, 7.710, 7.370, 7.320, 4.110, 5.050, 6.330, 7.020, 7.350, 7.600, 7.700, 7.740, 7.770, 7.750, 7.750, 7.710, 7.630, 7.560, 7.550, 7.400, 7.300, 7.190, 6.920, 6.420, 5.850, 5.720, 2.920, 4.350, 5.520, 6.230, 6.710, 6.920, 7.100, 7.160, 7.190, 7.180, 7.130, 7.050, 7.050, 6.970, 6.850, 6.660, 6.500, 6.320, 6.010, 5.320, 4.730, 4.570, 2.339, 3.940, 5.000, 5.620, 6.090, 6.280, 6.440, 6.570, 6.590, 6.610, 6.600, 6.500, 6.470, 6.340, 6.220, 5.920, 5.790, 5.550, 5.220, 4.670, 3.980, 3.840, 2.002, 3.725, 4.620, 5.170, 5.550, 5.770, 5.970, 6.100, 6.110, 6.120, 6.070, 6.020, 5.920, 5.800, 5.610, 4.420, 5.190, 4.950, 4.590, 4.070, 3.440, 3.392, 1.860, 3.549, 4.330, 4.790, 5.170, 5.350, 5.580, 5.620, 5.650, 5.660, 5.580, 5.520, 5.450, 5.310, 5.150, 4.800, 4.640, 4.390, 4.060, 3.580, 3.043, 3.035, 1.730, 3.404, 4.110, 4.520, 4.840, 5.010, 5.160, 5.210, 5.220, 5.220, 5.170, 5.110, 4.990, 4.870, 4.670, 4.350, 4.210, 3.960, 3.649, 3.215, 2.718, 2.711, 1.658, 3.301, 3.920, 4.300, 4.550, 4.700, 4.820, 4.840, 4.830, 4.810, 4.740, 4.650, 4.600, 4.450, 4.240, 4.030, 3.830, 3.571, 3.288, 2.900, 2.488, 2.460, 1.554, 3.212, 3.753, 4.110, 4.310, 4.420, 4.500, 4.500, 4.510, 4.450, 4.380, 4.310, 4.210, 4.070, 3.870, 3.627, 3.470, 3.259, 2.937, 2.636, 2.291, 2.243, 1.468, 3.137, 3.615, 3.920, 4.070, 4.130, 4.220, 4.230, 4.190, 4.130, 4.040, 3.980, 3.850, 3.740, 3.540, 3.338, 3.194, 3.010, 2.713, 2.414, 2.115, 2.087, 1.397, 3.069, 3.500, 3.764, 3.900, 3.920, 3.960, 3.940, 3.870, 3.830, 3.787, 3.660, 3.560, 3.427, 3.245, 3.035, 2.903, 2.717, 2.468, 2.222, 1.953, 1.948, 1.323, 2.984, 3.351, 3.616, 3.715, 3.711, 3.717, 3.670, 3.600, 3.540, 3.469, 3.350, 3.266, 3.139, 2.945, 2.760, 2.611, 2.475, 2.248, 2.009, 1.782, 1.758, 1.238, 2.892, 3.224, 3.450, 3.554, 3.465, 3.500, 3.451, 3.369, 3.313, 3.176, 3.097, 2.990, 2.894, 2.712, 2.524, 2.403, 2.240, 2.052, 1.847, 1.626, 1.610, 1.143, 2.779, 3.118, 3.313, 3.367, 3.289, 3.300, 3.193, 3.122, 3.056, 2.936, 2.835, 2.734, 2.622, 2.456, 2.288, 2.155, 2.057, 1.900, 1.679, 1.484, 1.483, 1.042, 2.689, 3.070, 3.161, 3.204, 3.100, 3.079, 2.982, 2.880, 2.800, 2.686, 2.600, 2.499, 2.383, 2.222, 2.070, 2.090, 1.839, 1.691, 1.513, 1.337, 1.325, 0.941, 2.703, 2.952, 3.043, 3.022, 2.931, 2.835, 2.761, 2.646, 2.584, 2.445, 2.360, 2.271, 2.165, 2.027, 1.846, 1.779, 1.656, 1.510, 1.351, 1.210, 1.211, 0.824, 2.643, 2.854, 2.901, 2.830, 2.709, 2.624, 2.523, 2.404, 2.339, 2.213, 2.131, 2.042, 1.936, 1.050, 1.658, 1.593, 1.457, 1.332, 1.210, 1.064, 1.064, 0.715, 2.850, 2.748, 2.718, 2.625, 2.477, 2.389, 2.275, 2.169, 2.084, 1.982, 1.900, 1.810, 1.731, 1.602, 1.468, 1.417, 1.307, 1.170, 1.071, 0.947, 0.946, 0.642, 2.767, 2.590, 2.506, 2.394, 2.241, 2.122, 2.025, 1.927, 1.893, 1.751, 1.743, 1.601, 1.554, 1.408, 1.285, 1.249, 1.142, 1.024, 0.919, 0.815, 0.830, 0.538, 2.651, 2.370, 2.212, 2.045, 1.930, 1.856, 1.741, 1.680, 1.840, 1.505, 1.470, 1.398, 1.320, 1.246, 1.097, 1.078, 0.992, 0.883, 0.787, 0.702, 0.702, 0.436, 2.381, 2.050, 1.791, 1.690, 1.601, 1.558, 1.497, 1.421, 1.360, 1.284, 1.231, 1.188, 1.107, 1.019, 0.924, 0.925, 0.852, 0.743, 0.668, 0.588, 0.601, 0.366, 1.947, 1.489, 1.298, 1.230, 1.211, 1.226, 1.199, 1.182, 1.220, 1.052, 1.008, 0.978, 0.930, 0.852, 0.735, 0.764, 0.706, 0.619, 0.560, 0.492, 0.474, 0.229];V=reshape(V,numel(X),numel(Y));contourf (X,Y,V)
"This weird thing only happens when i=1.6."
Nothing weird happens: you generate binary floating point numbers using two different methods and get slightly different output values for some input values. That is in the nature of binary floating point numbers.
"Is it a bug..."
No.
"...or is there something wrong with my code."
Yes. You assumed that numeric mathematics is the same as symbolic or algebraic mathematics. But it isn't.
In your example you did not take into account the acccumulated floating point error, which means that you should never test for exact equality of binary floating point numbers, but should always compare the absolute difference againsts a tolerance:
abs(A-B)<tol
Or change the algorithm to work with integer values only.
Read more about binary floating point numbers:
This is worth reading as well:
Best Answer