I am trying to compare two functions on the end points of an interval.
For instance, $f_1(t)=t^3$ and $f_2(t)=t^4$. From my code below I check whether $f_1(t)\leq f_2(t)$ when $t=50$ on $[50, 51]$ and if it is then I store values $\{\{f_1(50), f_2(50)\}\}$ and then I move to $t=51$ and store it as $\{f_1(50), f_2(50)\},\{f_1(51), f_2(51)\} \}$ and so on until I reach $t=55$. I am using Sow/Reap to build my list. Here is my code:
f1[t_] := t^3
f2[t_] := t^4
n = 0;
T = 50;
k = 1;
lst = {};
Reap[While[T + n*k <= 55,
If[f1[T + n*k] <= f2[T + n*k], Sow[{f1[T + n*k], f2[T + n*k]}];
n = n + 1, Print[T + n*k]]]
]
lst
My questions:
Using Reap/Sow in this manner gives me some extra $\{\}$ and an output of "Null" as my first element. What would be the correct way of using them in this case? (I wasn't able to get this clarification from their documentation.)
Is there a quicker way to build such a list since in application I will have large "t" of the order of $10^6$ or $10^7$ instead of $50$ (and complicated $f_1, f_2$)? So far Reap/Sow I found to be the fastest.
Join @@ Last@ Reap[While[T + n*k <= 55, If[f1[T + n*k] <= f2[T + n*k], Sow[{f1[T + n*k], f2[T + n*k]}]; n = n + 1, Print[T + n*k]]]]
$\endgroup$