For Loops for Summation Problems
이전 댓글 표시
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
KALYAN ACHARJYA
2018년 10월 7일
편집: KALYAN ACHARJYA
2018년 10월 7일
In this statement the value of x is not change
x1=80000-sum(0.1)
Whatever the number of iterations you performed
Stephen23
2018년 10월 7일
for k = 1:800000
x1 = 80000 - sum(0.1);
end
But nothing in your calculation depends on k, so I don't really see the point.
Shawna Myatt
2018년 10월 7일
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개)
카테고리
도움말 센터 및 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!