Never approached this kind of program before, need help.

1 Ansicht (letzte 30 Tage)
Rand Renwar
Rand Renwar am 2 Feb. 2016
Kommentiert: Star Strider am 3 Feb. 2016
So I'm supposed to write a program that calculates how many terms it takes for (1/1)+(1/2)+(1/3)+(1/4)...(1/n) shall be more than 4.
I can't use matlabs built-in functions (sum, sorting). Thank you!

Akzeptierte Antwort

Star Strider
Star Strider am 2 Feb. 2016
Use a while loop, and keep track of the accumulating sum in each iteration.
  2 Kommentare
Rand Renwar
Rand Renwar am 3 Feb. 2016
sorry but i don't understand. I am super new to matlab. Could you explain a bit more? Thank you
Best regards Rand Renwar
Star Strider
Star Strider am 3 Feb. 2016
I was thinking something like this:
series_sum = 0;
k1 = 0;
while series_sum <= 4
k1 = k1 + 1;
series_sum = series_sum + 1/k1;
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by