For Loops for Summation Problems

1 次查看(过去 30 天)
Shawna Myatt
Shawna Myatt 2018-10-7
评论: jonas 2018-10-7
I need to create a 'for' loop for the following summation:
x1 = 80000 - sum(0.1) from k=1 to k=800000. The point is to show that while this should equal zero, MatLab will add up all the minor errors until it creates one large one.
I have tried reading through the posts on here and watching videos, but I cannot figure out how to enter this into MatLab without getting an error or an infinite loop. I am very new to MatLab, so any help would be appreciated.
Thank you!
  4 个评论
Shawna Myatt
Shawna Myatt 2018-10-7
That is what I thought, but this is exactly how it is written in the problem. I thought it was an error, but there are four different problems like this with slightly different numbers, and none of them include a k value in the summation equation.
jonas
jonas 2018-10-7
Well, looking at your description of the problem, I guess you could do something like this
x1=80000;
for k = 1:800000
x1 = x1 - sum(0.1);
end
x1 =
-1.687279162776445e-07
so the answer is not zero, lesson learned.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by