Hi,
I have defined a recursive function using memoization
f[t_,x_]:=f[t,x]= ......
then i need to execute some sums like this
marg = -Sum[j*f[0, j], {j, -100, 100}];
this sum takes up to 0.85 sec in order to be executed, depending on the function (actually I have more recursive functions, and i use one sum like the previous one for each. Hence, my algorithm speed overall is too slow, resulting in 4,50 seconds about).
I tried two alternative methods to improve speed but unsuccesfully
1) using tables, and then function total, like this
pinakas = Table[i*f[0, i], {i, 0, 100}]
Total[pinakas]
2) using for function instead of Sum
s2=0
For[
i=0,i<=100,i++,
s2=s2+f[0,ι]
]
All methods (i guess thats logical) yield the same times more or less. I have setup my algorithm in an excel file, and while serial, my algorithm is superfast. I cannot understand why, but if I print all values needed from my function, print is instant (which means that each f[0,i] is really fast calculated) but this sum is so slow.
I though that It would be wise to limit precision somehow in my f[0,i] values, since I only need 3-4 digits, but I do not know how to exactly perform that. I even used decimals instead of integers (1.0 instead of 1 for example) as suggested in various guides, but this resulted in a decrease of speed.
So here I am, asking for your assistance.. unfortunately I cannot provide community with actual code, but I would appreciate any tip or assistance.
Regards