How do I create a vector that increases in size with decreasing increments?

I'm trying to create a vector that increases between 0 and 10, increasing rapidly at first and then plateauing with smaller increments towards 10.
For example: [0 4 7 9 10]
I have tried using logspace and exp with:
y1 = logspace(0,1,5);
and
X = 0:0.5:10;
Y = exp(X/2);
plot(X,Y)
but they produce the opposite result I am trying to achieve. I've searched the web using key words but haven't came across anything similar, I think the "increasing whilst decreasing" factor is skewing results.
Are there any functions I'm missing that produce this vector automatically?
Thanks in advance!

답변 (1개)

Stephan
Stephan 2018년 8월 13일
편집: Stephan 2018년 8월 13일
Hi,
this could meet your requirements:
a = 10;
x = 0:10;
y = a*exp(-1./x);
plot(x,y)
gives:
y =
0 3.6788 6.0653 7.1653 7.7880 8.1873 8.4648 8.6688 8.8250 8.9484 9.0484
.
If you need y to be integer use:
y = round(a*exp(-1./x));
Best regards
Stephan

카테고리

도움말 센터File Exchange에서 Language Fundamentals에 대해 자세히 알아보기

질문:

2018년 8월 13일

편집:

2018년 8월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by