필터 지우기
필터 지우기

how to create a sequence with percentage increments

조회 수: 1 (최근 30일)
Aya Zaatreh
Aya Zaatreh 2021년 8월 10일
편집: DGM 2021년 8월 10일
i want to create a squence of n numbers that start at 3 and go up in 10% increments. how would i do that?

답변 (2개)

Chunru
Chunru 2021년 8월 10일
n = 10;
x = 3*1.1.^(0:n-1)
x = 1×10
3.0000 3.3000 3.6300 3.9930 4.3923 4.8315 5.3147 5.8462 6.4308 7.0738

DGM
DGM 2021년 8월 10일
편집: DGM 2021년 8월 10일
Here's one way.
n = 15;
x0 = 3;
inc = 0.1;
x = ones(1,n-1)*(1+inc);
x = cumprod([x0 x])
x = 1×15
3.0000 3.3000 3.6300 3.9930 4.3923 4.8315 5.3147 5.8462 6.4308 7.0738 7.7812 8.5594 9.4153 10.3568 11.3925
There are probably simpler ways with a bit of math. You could do it with a simple exponential if you just calculate the right parameter.
x2 = 0:n-1;
x2 = x0*exp(log(1+inc)*x2)
x2 = 1×15
3.0000 3.3000 3.6300 3.9930 4.3923 4.8315 5.3147 5.8462 6.4308 7.0738 7.7812 8.5594 9.4153 10.3568 11.3925
Whichever one of these three options is fastest depends on the vector length and version/environment.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by