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

14 visualizzazioni (ultimi 30 giorni)
How I can code this vector x=[1; 1/2;1/3; ......;1/(n-1)] n=15 ?
  6 Commenti
Stephen23
Stephen23 il 24 Set 2018
Modificato: Stephen23 il 24 Set 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.

Accedi per commentare.

Risposta accettata

Bish Erbas
Bish Erbas il 24 Set 2018
Modificato: Bish Erbas il 24 Set 2018
Try:
n = 15;
x = 1./(1:n-1);

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by