How do I create a sequence which goes from 1 to .000001?

3 Ansichten (letzte 30 Tage)
John Smith
John Smith am 9 Okt. 2017
Kommentiert: Jan am 10 Okt. 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 Kommentare
per isakson
per isakson am 9 Okt. 2017
  • 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.
John Smith
John Smith am 9 Okt. 2017
It's not a hw question, its a review question for a test. 1:-.1:0 1:-.01:0 linspace(1,0,6)
I would think these solutions would work. An example above this question which I had gotten correct was: 7,13,19......37,43,49 The command I entered was 7:6:49
^ that is correct because if you enter that in MatLab, you can obviously see it is correct.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 9 Okt. 2017
Bearbeitet: Jan am 9 Okt. 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 Kommentare
John Smith
John Smith am 9 Okt. 2017
Yes, this worked and was along the lines of what I was supposed to get. Thanks Jan, if you don't mind me asking, how is that explained in matlab? Meaning, what is happening to make the outcome 1, .1, .01 etc. I believe I have the first part but lose it after the second part. 10^0 is 1, but if you -1 the answer would then be 0.
Jan
Jan am 10 Okt. 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]

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by