One can integrate Derivative[0, 1][y][x, t]^2
along with the pde
:
pde = D[y[x, t], t, t] == D[y[x, t], x, x];
solnDerivative =
NDSolve[{pde, y[x, 0] == Exp[-(x)^2], Derivative[0, 1][y][x, 0] == 0,
Derivative[1, 0][y][-50, t] == Derivative[0, 1][y][-50, t],
Derivative[1, 0][y][50, t] == -Derivative[0, 1][y][50, t],
(**)
Derivative[0, 1][int][x, t] == Derivative[0, 1][y][x, t]^2,
int[x, 0] == 0},
{Derivative[0, 1][y][x, t], int[x, 130]}, {x, -50, 50}, {t, 0, 130}]
The integral may be obtained and a value for x
substituted with
int[x, 130] /. First@solnDerivative /. x -> 10
Here is a plot (on the grid generated by NDSolve
), which seems a little wobbly around x == 0
:
ListLinePlot[{x, int[x, 130] /. First@solnDerivative} /. x -> # & /@
Head[Derivative[0, 1][y][x, t] /. First@solnDerivative]["Grid"][[All, 1, 1]],
PlotRange -> All]
Here are some values of int[x, 130]
compared with the result of integrating the derivative from the computed derivative Derivative[0, 1][y][x, t]
, with values of x
taken among the grid computed by NDSolve
:
Table[{
int[x, 130] /. First[solnDerivative],
(int[x, 130] /. First[solnDerivative]) -
NIntegrate[Derivative[0, 1][y][x, t]^2 /. First[solnDerivative],
Evaluate@
Prepend[Head[Derivative[0, 1][y][x, t] /. First@solnDerivative]["Grid"][[1, All, 2]], t]]},
{x, Head[Derivative[0, 1][y][x, t] /. First@solnDerivative]["Grid"][[All, 1, 1]][[;; ;; 37]]}]
(*
{{0.317956, -0.00806953}, {0.324704, 0.0000186443}, {0.326885, 2.02759*10^-6},
{0.334907, 0.000021252}, {0.340367, 0.0000134228}, {0.342387, 0.00011331},
{0.341913, 0.000136063}, {0.657123, -0.000169644}, {0.344552, 0.000135694},
{0.348381, 0.000113308}, {0.356022, 0.0000133392}, {0.374857, 0.0000212584},
{0.400694, 1.89176*10^-6}, {0.405668, 0.0000179112}, {0.423675, -0.00942803}}
*)
V8 Code
The code above does not run on V8.0.4. The return expression int[x, 130]
with the value 130
for t
. My preference is to return the InterpolatingFunction
without the arguments. Another issue is that the code complains about a spatial error estimate being too great (with a grid of 933 points). Setting "MinPoints"
to 1000
solves that problem.
solnDerivative =
NDSolve[{pde, y[x, 0] == Exp[-(x)^2], Derivative[0, 1][y][x, 0] == 0,
Derivative[1, 0][y][-50, t] == Derivative[0, 1][y][-50, t],
Derivative[1, 0][y][50, t] == -Derivative[0, 1][y][50, t],
(**)
Derivative[0, 1][int][x, t] == Derivative[0, 1][y][x, t]^2, int[x, 0] == 0},
{Derivative[0, 1][y], int},
{x, -50, 50}, {t, 0, 130},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 1000}}]
The rest of the code above may be used as is. One might want to change the 37
to something like 100
in the Table
example.
integratedFunction = Integrate[(ifunDerivative[x, t])^2, {t, 0, 130}, x]
. Do you want indefinite integral with respect tox
followed by the definite integral with respect tot
? $\endgroup$