n term series using For loop

10 ビュー (過去 30 日間)
marie
marie 2013 年 3 月 13 日
n=input('enter a value n:');
s=0;
k=1;
for k=<n
s=s+k;
k=k+1;
end
I was trying to change my while loop for this one (for loop) to see if the results were the same but when i type the code it says unexpected matlab operator The code was working for the while loop
  1 件のコメント
Matt J
Matt J 2013 年 3 月 13 日
In the for loop version, you would remove this line
k=k+1;

サインインしてコメントする。

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 13 日
It's
for k=1:n

Gilles
Gilles 2013 年 3 月 13 日

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by