I have two functions that I both use memoization for. My goal is to plot the ratio of these two functions. Since I already plot the functions by themselves, and I use memoization, it would seem to me that this shouldn't take much time. However, it still runs very slowly, suggesting to me that the memoization doesn't work as I had intended.
mem : f1[x_?NumericQ] := mem = (*slow function 1*)
mem : f2[x_?NumericQ] := mem = (*slow function 2*)
mem : f3[x_?NumericQ] := mem = f1[x]/f2[x]
Plot[f1[x], {x,0,1}]
Plot[f2[x], {x,0,1}]
Plot[f3[x], {x,0,1}]
All three plots are slow, but I would expect the third one to be fast since the relevant details have been calculated in the previous two plots. My guess is that Plot
uses different x-values for the third plot than the ones that are stored in memory, possibly due to the fact that these x-values for f1
and f2
differ. Is there a way to speed up this procedure?