I should define a function which sums up from k=0
to 100
, with x=1
; using the Do
function and modules; without using the Sum
function
I tried it this way:
blub[x_, p_]:=Do[blub=((-1)^k/x^k), {k, 1, p}]
blub[1, 100]
Problems:
- I don't get any output
- I don't get why I would need a module
I would be glad if someone could help me.
Thanks for the fast help, Solution number 2 fits perfect for what I want.
Is there a posibility that I use a module inside the iterator? So that I can use my function this way.
v=0;
f[x_, n_]:=Do[v +=((-1)^n/x^n), {n, 1, n}]
f[1, 100]
v
Is there a posibility to make this work without changing one of the n's into another variable name (I`m aware that I double defined one variable)