From: Walter Roberson on 20 Mar 2010 01:28 Alex wrote: > As a specific example: > > I want 256 integer points ~ log spaced ranging between 0 (or 1 if you > really want to use logspace) and 65536. If I run logspace, I get a bunch > of duplicates. If I remove the duplicates, I have < 256 points (it has > to be 256). > > The solution I came up with is to just look at the place where logspace > stops duplicating (around 30) and then do a logspace of 226 points > between 30 and 65536 and then just add 1:30 to the left of the array. Let delta = 65535^(1/373) . Then there are 256 distinct (after rounding) logarithmically spaced values starting from delta^118 and ending at 65535. delta^118 rounds to 33. Your problem statement did not require that there be no noticeable gap between 0 and the first value, or that the gap between the last and 65536 be logarithmically spaced, only that the values that were chosen round to distinct integers and that there were 256 of them that were less than 65536. The complete list is [33, 34, 35, 37, 38, 39, 40, 41, 42, 44, 45, 46, 48, 49, 51, 52, 54, 55, 57, 59, 61, 62, 64, 66, 68, 70, 72, 75, 77, 79, 81, 84, 86, 89, 92, 95, 97, 100, 103, 106, 110, 113, 116, 120, 124, 127, 131, 135, 139, 143, 148, 152, 157, 161, 166, 171, 177, 182, 187, 193, 199, 205, 211, 217, 224, 231, 238, 245, 252, 260, 268, 276, 284, 293, 301, 311, 320, 330, 340, 350, 360, 371, 382, 394, 406, 418, 431, 444, 457, 471, 485, 500, 515, 530, 546, 563, 580, 597, 615, 634, 653, 673, 693, 714, 736, 758, 781, 804, 828, 854, 879, 906, 933, 961, 990, 1020, 1051, 1083, 1115, 1149, 1184, 1219, 1256, 1294, 1333, 1373, 1415, 1458, 1502, 1547, 1594, 1642, 1691, 1742, 1795, 1849, 1905, 1962, 2022, 2083, 2145, 2210, 2277, 2346, 2416, 2489, 2564, 2642, 2721, 2804, 2888, 2975, 3065, 3158, 3253, 3351, 3452, 3556, 3664, 3774, 3888, 4006, 4127, 4251, 4379, 4512, 4648, 4788, 4932, 5081, 5235, 5393, 5555, 5723, 5896, 6074, 6257, 6446, 6640, 6841, 7047, 7260, 7479, 7705, 7937, 8177, 8423, 8678, 8940, 9209, 9487, 9774, 10069, 10372, 10685, 11008, 11340, 11682, 12035, 12398, 12772, 13158, 13555, 13964, 14385, 14819, 15267, 15727, 16202, 16691, 17195, 17714, 18248, 18799, 19366, 19951, 20553, 21173, 21812, 22470, 23149, 23847, 24567, 25308, 26072, 26859, 27670, 28505, 29365, 30251, 31164, 32105, 33073, 34072, 35100, 36159, 37250, 38375, 39533, 40726, 41955, 43221, 44525, 45869, 47253, 48679, 50149, 51662, 53221, 54827, 56482, 58186, 59943, 61752, 63615, 65535] The general form is: approxdel = fzero(@(delta) 1/delta*(1+delta)^(N-1)-(A-1)); c = ceil( -ln(approxdel)/ln(1+approxdel) ); delta = (A-1)^(1/(c+N-1)); points = round((1+delta).^(c:c+N-1)); The derivation of this is left as an exercise to the reader ;-)
First
|
Prev
|
Pages: 1 2 Prev: Plotting data with nonuniform mesh/grid? Next: Popup message in Matlab Gui |