# Plot with Mathematica

How Can I plot the following figures for the following equations?

$x\in\mathbb{R}, f(x) = \frac{\left|\sin(x)\right|}{x^2+x+1}$

$t\in\mathbb{R}, A(t)=\displaystyle\int_t^{t+2\pi}\!\dfrac{|\sin x|}{x^2+x+1}\mathrm{d}x$

Details of The graphs • I vote that Mark McClure answer this one (see OPs link). Dec 12, 2014 at 20:32
• At least vote him up. Dec 12, 2014 at 20:40
• As Mark's comment on his answer states, the code is given in the answer source. Here it is at the bottom: math.stackexchange.com/revisions/…
– user484
Dec 12, 2014 at 20:44
• @Rahul, Thanks. I find it and produce it to a gif image. Dec 12, 2014 at 21:33

f[x_] := Abs@Sin@x/(x x + x  + 1)
a[t_] := NIntegrate[f[x], {x, t, t + 2 Pi}]
tabA = Table[{t, a[t]}, {t, -3 Pi, 3 Pi, 6 Pi/100}];
opc = Sequence[ImageSize -> 400,  Ticks -> {Array[- 4 Pi + # Pi &, 6], Automatic}];
Animate[Column[{
Show[Plot[f[x], {x, -3Pi, 3Pi}, AspectRatio->1/4, Evaluate@opc, PlotRange->{{-3 Pi, 3 Pi}, All}],
Plot[f[x], {x, tabA[[p, 1]], tabA[[p, 1]] + 2 Pi}, Filling -> Axis]],
Text["area = " <> ToString@N@tabA[[p, 2]]],
ListLinePlot[tabA, Evaluate@opc, Epilog -> {PointSize@Large, Point[tabA[[p]]]}]}, Center],
{p, 1, Length@tabA, 1}] • nice. but no control buttons :) Dec 13, 2014 at 0:46
• @Nasser I posted this one only because you were too lazy to note that the Op's model doesn't have buttons :D Dec 13, 2014 at 2:49

It took me few minutes to figure what it is doing. But here is a Manipulate. I did not know the code is there and did not look at original one yet. I am sure it is done better than my attempt here: Manipulate[
tick;
If[state == "RUN",
tick = Not[tick];
a = a + 0.1;
If[a > 4 Pi,
state = "RESET";
a = -4 Pi;
cArea = {}
]
];

Module[{area, g},
area = NIntegrate[f, {x, a, a + 2 Pi}];
g = Grid[{{
Show[
Plot[f, {x, -4 Pi, 4 Pi},
PlotRange -> {{-4 Pi, 4 Pi}, {0, .9}},
PlotLabel -> Row[{"Area = ", area}]
],

Plot[f, {x, a, a + 2 Pi}, Filling -> Bottom],

PlotRange -> {{-4 Pi, 4 Pi}, {0, .9}}, ImageSize -> 400
]
},
{
AppendTo[cArea, {a, area}];
ListPlot[cArea, Joined -> True,
PlotRange -> {{-4 Pi, 4 Pi}, {0, 2}},
Epilog -> Point[{a, area}],
Ticks -> {{-4 Pi, -2 Pi, 0, 2 Pi, 4 Pi, 2}, Automatic}]
}
}, Frame -> All];
g
],

Grid[{{Button[Text@Style["run", 12], {state = "RUN"; tick = Not[tick]},
ImageSize -> {60, 40}],
Button[Text@Style["stop", 12], {state = "STOP"; tick = Not[tick]},
ImageSize -> {60, 40}],
Button[Text@Style["reset", 12], {state = "RESET"; a = -4 Pi;
cArea = {}; tick = Not[tick]}, ImageSize -> {60, 40}]}},
Spacings -> {.5, 0}, Frame -> True, FrameStyle -> Gray
],

{{a, -3.99 Pi}, None},
{{cArea, {}}, None},
{{tick, False}, None},
{{state, "STOP"}, None},
TrackedSymbols :> {tick},
SynchronousUpdating -> True,
Initialization :>
(
f = Abs[Sin[x]]/(x^2 + x + 1)
)
]