Mathematica gives wrong result while Wolfram|Alpha is correct
Artes' guess seems basically right. Here is a way to reach the correct result. First, the antiderivative returned by Mathematica:
i0 = FullSimplify[
Integrate[Sqrt[(2 t)^2 + (4 - 3 t^2)^2], t],
t > 0]
(* (2 (Sqrt[16 - 2 I (-5 I + Sqrt[11]) t^2] Sqrt[8 + I (5 I + Sqrt[11]) t^2] (
5 (-5 I + Sqrt[11]) EllipticE[ArcSin[1/2 t Root[9 - 5 #1^2 + #1^4 &, 4]],
1/18 (7 - 5 I Sqrt[11])] -
(11 I + 5 Sqrt[11]) EllipticF[ArcSin[1/2 t Root[9 - 5 #1^2 + #1^4 &, 4]],
1/18 (7 - 5 I Sqrt[11])]) +
9/2 t (16 - 20 t^2 + 9 t^4) Root[36 + 10 #1^2 + #1^4 &, 3])) /
(27 Sqrt[(-5 - I Sqrt[11]) (16 - 20 t^2 + 9 t^4)]) *)
If we add to Pi
to the two ArcSin
expressions in i0
, we get another antiderivative:
i1 = i0 /. a_ArcSin :> Pi + a;
D[i0, t] // FullSimplify[#, t > 0] &
D[i1, t] // FullSimplify[#, t > 0] &
(* Sqrt[16 - 20 t^2 + 9 t^4]
Sqrt[16 - 20 t^2 + 9 t^4] *)
It turns out that i1
is the continuation of i0
:
Plot[{i0, i1}, {t, 0, 2},
PlotStyle -> {Directive[Thick, Blue], Directive[Thick, Red]}]
Hence,
(i1 /. t -> 2.) - (i0 /. t -> 0.)
(* 7.847 - 8.88178*10^-16 I *)
yields the correct (approximate) result.
Such are the pitfalls of elliptic integrals and their symbolic antiderivatives, I suppose. NIntegrate
bypasses antiderivatives and estimates the integral from the (real) values of the integrand. It should never encounter such problems.
Further analysis
The plots below show the discontinuities in the EllipticE
and EllipticF
that lead to the incorrect value for Integrate
. The discontinuities violate the conditions necessary to apply the Fundamental Theorem of Calculus (an antiderivative is by definition supposed to be differentiable and therefore continuous).
{x0, x1} = FixedPoint[ (* find the discontinuity *)
Function[{x}, If[Im@Chop[i0 /. t -> x] != 0, {First[#], x}, {x, Last[#]}]][Mean[#]] &,
{1.599, 1.6}]
Table[
With[{part = part, ell = ell},
ContourPlot[
part[ell[ArcSin[1/2 t Root[9 - 5 #1^2 + #1^4 &, 4]],
1/18 (7 - 5 I Sqrt[11])]] /. t -> x + I y,
{x, 0, 2}, {y, -1, 1},
MaxRecursion -> 3, PlotPoints -> 25,
AxesOrigin -> {x0, 0}, Axes -> True,
AxesStyle -> Directive[Thin, Red], PlotLabel -> part@ell]
],
{ell, {EllipticE, EllipticF}}, {part, {Re, Im}}] // GraphicsGrid
(* {1.5991767250934696`, 1.5991767250934699`} *)
To get the real-valued antiderivative, piece together different branches:
anti = Piecewise[{
{i0, -x0 <= t <= x0},
{i0 /. a_ArcSin :> Pi + a, t >= x1},
{i0 /. a_ArcSin :> -Pi + a, t <= -x1}},
Indeterminate];
Plot[anti, {t, -4, 4},
Mesh -> {{-x0, x0}}, MeshShading -> {Green, Blue, Red}]
This does not really answer the question as to why Mathematica's Integrate
yields an apparently wrong answer. This simply states why the two answers are different. It seems Wolfram|Alpha does not attempt to do a symbolic integration (which is what your input asks for) before taking its numerical value. As I stated in my comment, using NIntegrate
gives the correct answer similar to Wolfram|Alpha
. So, in short, Wolfram|Alpha
uses NIntegrate
directly. Which is why the following input yields the right answer in Mathematica:
NIntegrate[Sqrt[(2 t)^2 + (4 - 3 t^2)^2], {t, 0, 2}]
7.847
This is not an answer, but comparing the answer with Maple, and also showing step by step integration using Rubi, which might help point to where Mathematica went wrong.
Mathematica Integrate
r = Simplify@Integrate[Sqrt[(2 t)^2 + (4 - 3 t^2)^2], t]
N[r /. t -> 2 - r /. t -> 0, 20]
Maple
r:=int(sqrt( (2*t)^2+(4-3*t^2)^2),t=0..2);
evalf[20](r);
7.8469978240383303061+7.9695375019434005093*10^(-20)*I
F
in the above is EllipticF
and E
is EllipticE
. So both Maple and Mathematica have the answer in terms of Elliptic functions. To see step by step process, with the hope to better find where the bug happens, I used Rubi:
Rubi 4.2 step by step
ShowSteps = True;
r = Int[Sqrt[(2 t)^2 + (4 - 3 t^2)^2], t]
result = %;
N[result /. t -> 2 - result /. t -> 0, 20]
In one of those steps, the Integrate went wrong. Need more time to analyze.