how I can code this vector x=[1; 1/2;1/3; ......;1/(n-1)] n=15 ?

14 views (last 30 days)
How I can code this vector x=[1; 1/2;1/3; ......;1/(n-1)] n=15 ?
  6 Comments
Stephen23
Stephen23 on 24 Sep 2018
Edited: Stephen23 on 24 Sep 2018
n = 15;
v = zeros(n-1,1);
for k = 1:n-1
v(k) = 1/k;
end
But Bish Erbas's answer is preferred.

Sign in to comment.

Accepted Answer

Bish Erbas
Bish Erbas on 24 Sep 2018
Edited: Bish Erbas on 24 Sep 2018
Try:
n = 15;
x = 1./(1:n-1);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!