how to get 1 to 500 odd numbers sum in matlab?
3 views (last 30 days)
Show older comments
how to get 1 to 500 odd numbers sum in matlab?
2 Comments
Jan
on 7 May 2016
Because this is a homework question and the OP did not show any own effort, I suggest to accept Azzi's answer.
Image Analyst
on 7 May 2016
It wasn't tagged as homework and he didn't say it was homework, but it sounds a lot like it could be. That's always the dilemma : if it sounds and looks like homework but they didn't say so explicitly, do you (1) assume it's homework, ask them, and just give hints, or (2) assume it's not homework and give the full solution which means they would be plagiarizing if they used it as their homework answer? No clear answer. I will variously do both 1 and 2 on different questions depending on what I feel like at the time. Often times (2) happens and then panicky posters come back and obliterate their questions and comments which angers the rest of us because it makes us feel like we wasted our time.
Answers (3)
Roger Stafford
on 7 May 2016
sum is (1+499)*250/2
Note: Legend has it that ten-year-old Carl Friedrich Gauss was given a similar problem by his instructor. Instead of tediously adding up all the terms, he imagined that a like series in reverse order was matched up with the given series, and the matched pairs would thus always add up to the same value, so the problem was therefore transformed into one of simple multiplication and then division by two. Your problem is like that.
1 Comment
Jan
on 7 May 2016
While Image Analyst's solves the problem "in Matlab" as requested, this answer focusses on how a programmer can do the main part by thinking and Matlab has to solve a tiny calculation also. If the programmer can even multiply 500*125, he could use at least the cardboard box the Matlab DVDs are shipped in to sit on - but unfortunately modern Matlab versions are delivered by downloads.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!