- Homework?
- "I've tried so many different answers but nothing worked" Show us one or two of the most promising and we might to able to improve on them.
How do I create a sequence which goes from 1 to .000001?
2 views (last 30 days)
Show older comments
How do I create a sequence which will go from 1 to .000001 looking like this:
1.0 0.1 .01 .001 .0001 .00001 .000001
It seems simple and I've tried so many different answers but nothing worked. I tried
1:-.1:0, 1:-.01:0,
amongst many other ways turned out to be duds.
2 Comments
per isakson
on 9 Oct 2017
Accepted Answer
Jan
on 9 Oct 2017
Edited: Jan
on 9 Oct 2017
The power operator is expensive. It is more efficient to use
cumprod(repmat(0.1, 1, 6))
If this is a homework, I leave the last step up to you.
[EDITED] What about:
10 .^ (0:-1:-6)
4 Comments
Jan
on 10 Oct 2017
but if you -1 the answer
It is a bold speculation that a 1 is subtracted from 10^0 here. Split the expression into parts, to understand it:
(0:-1:-6)
This part is included in parenthesis, such that it is evaluated at first. You have learned something about the colon operator already: "a:b:c" means: start at a and add b until c is reached. This works with a negative b also.
The second part is 10 .^ .... "^" is the power operation, and ".^" means, that it is applied elementwise. Without the dot it would be a matrix operation.
Finally you get:
10 .^ [0,-1,-2,-3,-4,-5,-6]
or equivalently:
[10^0, 10^-1, 10^-2, ... 10^-6]
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!