# Summation with Do and For functions

Posted 10 years ago
5790 Views
|
4 Replies
|
5 Total Likes
|
 How exactly do I attack these problems?? the best I can come up with is ...For[Print[8/(10^x)], {x, 2, 16, 2}]Thanks All! 4 Replies
Sort By:
Posted 10 years ago
 You may also consider the numeric approximation using N, Total and Table:In:= f[max_]:=N[Total[Table[8/(10^n),{n,2,max,2}]],max]In:= fOut= 0.08080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080
Posted 10 years ago
 You appear to be testing to see if the n-term approximation to the infinite sum is sufficient.SumConvergence says that the sum converges unconditionally:In:= SumConvergence[8/10^(2 n), n]Out= Trueand Sum gives the value to which the infinite series converges:In:= Sum[8/10^(2 n), {n, Infinity}]Out= 8/99Best regards,David
Posted 10 years ago
 In Mma you dislike to use Do[], For[] or While[] for such an excercise because there is Table[]:In:= N[8 (Plus @@ Table[10^(-2 o), {o, 0, 7}])/100, 32]Out= 0.080808080808080800000000000000000If you are forced to use For[], you writeIn:= Block[{x = 0}, For[o = 1, o < 9, o++, x += 8 10^(-2 o)]; N[x, 32]]Out= 0.080808080808080800000000000000000If you are forced to use Do[], you writeIn:= Block[{x = 0}, Do[x += 8 10^(-2 o), {o, 1, 8}]; N[x, 32]]Out= 0.080808080808080800000000000000000If you are forced to use While[¨], you writeIn:= N[Block[{x = 0, o = 1}, While[o < 9, x += 8 10^(-2 o); o++]; x], 32]Out= 0.080808080808080800000000000000000If you are forced to use the Do[] with a condition on the iteration variable you compute that conditionIn:= N[Block[{x = 0}, Do[x += 8 10^(-2 o), {o, 1, Ceiling[Log[10, 8/0.0001]]}]; x], 32]Out= 0.080808080800000000000000000000000RegardsUdo.
Posted 10 years ago
 1) Suppose you started with a variable, set that equal to zero,  inside your For you added something to the variable that was computed from your x value and after the For is done perhaps do something useful with the variable?2) and 3) A For (sort of) automatically does some things for you. A Do and a While do a little less and leave those things to do for yourself. Can you again suppose you start with a variable, look at the help page for Do and While and try to think how to sort of make the same things happen with a little code you write yourself? You might also look at the help page for Break and see if that might or might not be useful.Did they perhaps mention anything that might seem similar to this in class?Hopefully those hints will be enough to get you started.I hope it works out