0
$\begingroup$

I am solving the following PDE:

T = 1 + 2/2 (1 + Tanh[(x - 0.5) 8])
Q = -D[T, x]
eqn1 := G[x, v] - D[(1/3)*D[G[x, v], x], x] == (-v^4)*Exp[-v]*D[Q, x]

sol = NDSolve[eqn1, G, {x, 0, 1}, {v, 0, 15}]

and plot the solution

DensityPlot[G[x, v] /. sol, {x, 0, 1}, {v, 0, 15}]

which looks well-behaved. However, when I try to integrate the solution over one of the variables (v), Mathematica says "The integrand has evaluated to Overflow, Indeterminate, or Infinity for all sampling points in the region with boundaries":

intGdv = FunctionInterpolation[NIntegrate[G[x, v] /. sol, {v, 0, 15}], {x, 0, 1}]

Eventually, I want to differentiate this integral wrt x, i.e. to find $\partial_x(intGdv)$. What function can I use to perform this differentiation and why does Mathematica complain about the quality of the integrand above?

$\endgroup$
1
$\begingroup$

Instead of trying to manipulate the output of NDSolve, it is much easier to just augment the NDSolve so that it directly outputs what you need. For example:

{gsol, intGdv} = NDSolveValue[
    {eqn1, D[int[x,v], v] == G[x, v], int[x, 0] == 0},
    {G, int},
    {x, 0, 1},
    {v, 0, 15}
];

NDSolveValue::femibcnd: No DirichletCondition or Robin-type NeumannValue was specified for {G}; the result may not be unique.

Here are some density plots of the integral and its derivative:

DensityPlot[intGdv[x, v], {x, 0, 1}, {v, 0, 15}]
DensityPlot[Derivative[1, 0][intGdv][x, v], {x, 0, 1}, {v, 0, 15}]

enter image description here

$\endgroup$
  • $\begingroup$ How did you know it was easier this way? If I want to form lots of different new functions from the solution G, do I have to include them all in the call to NDSolve, is there no way to manipulate the output of NDSolve afterwards? Why did you use NDSolveValue instead of NDSolve? Your plot of the derivative appears much "smoother" and better looking than mine when I run your code, what version of Mth are you using (I have v10.3.1)? $\endgroup$ – kotozna Nov 9 '17 at 6:12
  • $\begingroup$ @kotozna NDSolve produces an approximation, and NIntegrate tries to produce a result with some prescribed precision goal. This is hard to do when the integrand is not accurate, and is why NIntegrate complains. Including the integral in NDSolve makes NDSolve work a bit harder to adjust the steps so that both the original function and its integral are computed accurately. I use NDSolveValue because I find it easier to use. I use M11.2, and I agree that the output has improved. $\endgroup$ – Carl Woll Nov 9 '17 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.