- 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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
John Smith
el 9 de Oct. de 2017
Comentada: Jan
el 10 de Oct. de 2017
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 comentarios
per isakson
el 9 de Oct. de 2017
Respuesta aceptada
Jan
el 9 de Oct. de 2017
Editada: Jan
el 9 de Oct. de 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 comentarios
Jan
el 10 de Oct. de 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]
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!