Summation with FOR loop question
2 ビュー (過去 30 日間)
古いコメントを表示
I am fairly new to MATLAB. How do you get an answer for this using a FOR loop?

0 件のコメント
採用された回答
Mark Sherstan
2019 年 2 月 14 日
編集済み: Mark Sherstan
2019 年 2 月 14 日
Please take the time to fully understand what is going on but this should get you started.
f = 0; % Set the initial conditions
for ii = 0:1600 % Looping from 0 to 1600 as denoted in the summation
f = f + 1/factorial(ii); % Add the previous response to the new response (hence summation)
end
fprintf("The answer is %0.3f\n",f) % Display the answer to 3 decimal places
0 件のコメント
その他の回答 (2 件)
Geoff Hayes
2019 年 2 月 14 日
Oliver - since this is most likely homework and I'm assuming that you have been instructed to use a for loop, see for loop to repeat specified number of times and factorial. An alternative to using a loop is vecorization..see using vectorization for more details.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!