Generate a numerical series
古いコメントを表示
Hi everyone, I want to generate this vector: 1e-8, 1e-9, 1e-10, 1e-11, 1e-12, 1e-13, 1e-14.
How can i do it?
Thanks
1 件のコメント
採用された回答
その他の回答 (1 件)
John D'Errico
2022 年 1 月 28 日
編集済み: John D'Errico
2022 年 1 月 28 日
While @DGM is correct (+1 from me on that answer, please accept that answer, as it is the correct one), in that it is what I would do immediately, there are always many ways to do things like this. The alternative I can think of immediately is to use cumprod with repmat:
format long g
v = cumprod([1e-8,repmat(0.1,1,6)])
fprintf('%g\n',v.') % for sake of clarity
I could also have used cumprod, in conjunction with repelem instead of repmat. That would be slightly less kludgy looking.
cumprod([1e-8,repelem(0.1,6)])'
Then I think of logspace, which does work nicely. In fact, logspace is a pretty clean looking solution. Still not as obvious in my eyes as that which DGM proposed.
logspace(-8,-14,7).'
And of course, there is this devious solution:
exp((-8:-1:-14)*log(10)).'
which is technically correct, exceot that floating point trash appears in the least significant bits. But 9.99999999999999e-9 is technically 1e-8, exept for an error in the least significant bit of the result.
I can stop here, but with some effort, I'd bet there are more.
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!