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

4 Ansichten (letzte 30 Tage)
MAK
MAK am 23 Sep. 2018
Kommentiert: Arun Singh am 7 Sep. 2022
How I can code this vector x=[1; 1/2;1/3; ......;1/(n-1)] n=15 ?
  6 Kommentare
Stephen23
Stephen23 am 24 Sep. 2018
Bearbeitet: Stephen23 am 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.
Arun Singh
Arun Singh am 7 Sep. 2022
for n= 1:50
fprintf("1/"+n+", ")
end
Try this

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by