# Continuing summation till the magnitude of the terms become smaller than a value

I've tried to plot the below density plot. But since there is a summation inside the plot and the term inside the summation goes to zero differently for different values of $$a$$ and $$t$$, I need to tell the summation that continues till the value of the term inside the summation becomes smaller than a certain value say $$0.01$$. How can I do that?

     DensityPlot[
Sum[(a^(1 + 2 mz) Sin[(3 + 2 mz) t]), {mz, 0, 100}], {a, 0.1, 0.2}, {t, 0, Pi/2}]

• In the Sum, the summation variable m does not appear in the Sum. Is the variable supposed to be mz or should mz actually be m*z? Since you are plotting, what values are you using for the undefined parameters (e.g., p1)? – Bob Hanlon Dec 2 '19 at 22:29
• Thanks. I've edited the code @BobHanlon – Marco Dec 2 '19 at 22:39
• Nest and FixedPoint might be worth mentioning. – Carl Lange Dec 2 '19 at 23:41
• How should I use them? @CarlLange – Marco Dec 3 '19 at 8:10

A procedural method is just to make a function of a while loop.

whilesum[a_, t_] := Block[
{mz = 0.,
term = (-16 a^(2 + 4 mz) - 8 (-1)^mz a^(1 + 2 mz) (Sin[(3 + 2 mz) t] - Sin[t - 2 mz t]))/((-1 + a^(2 + 4 mz)) (1 + 2 mz) \[Pi]),
total = 0.},
While[
term >= 0.01,
total += total + term;
mz++
];
total
]

DensityPlot[
whilesum[a, t],
{a, 0.1, 0.2},
{t, 0, Pi/2}
]


• When I run your code, I just get a blue totally blue plot with some white regions! – Marco Dec 2 '19 at 23:10
• @Marco Woops, thanks for the catch! I changed expr to term at the last minute and missed one. – NonDairyNeutrino Dec 2 '19 at 23:15
• Thanks, Could you please modify the term? I edited the term in the question so that the question seems more general. – Marco Dec 2 '19 at 23:26