I'm trying numerically solve a PDE using NDSolve
. I keep getting the following error:
"NDSolve::ndnum: "Encountered non-numerical value for a derivative at t == 0.."
It seems that I only get this error due to the presence of Abs[D[f[x,y,t],x]]
or Conjugate[D[f[x,y,t],x]]
. I created a very simple function to demonstrate this problem.
This will work:
noAbs = D[f[x, t], t] == f[x, t] f[x, t] D[f[x, t], x, x]
xrange = \[Pi]; trange = 5;
forSolve = {noAbs, f[x, 0] == Exp[I x], f[-xrange, t] == f[xrange, t]}
frul = NDSolve[forSolve, f, {x, -xrange, xrange}, {t, 0, trange},
MaxStepSize -> 0.007, Method -> "MethodOfLines" ];
This won't work (note the only difference is that we don't have an Abs).
withAbs = D[f[x, t], t] == f[x, t] f[x, t] Abs[D[f[x, t], x, x]];
forSolve = {withAbs, f[x, 0] == Exp[I x],
f[-xrange, t] == f[xrange, t]}
frul = NDSolve[forSolve, {f}, {x, -xrange, xrange}, {t, 0, trange},
MaxStepSize -> 0.007, Method -> "MethodOfLines" ];
Plot3D[Re[f[x, t]] /. frul, {x, -xrange, xrange}, {t, 0, trange}]
Right now I'm guessing Mathematica tried to take derivatives of my expressions and finds that it doesn't know how to derive Abs
function. Am I right in assuming this, and how does one get around this problem?
With a little patience and writing everything in terms of the real and imaginary part of your function.
Setting f=fRe + I fIm
:
equation = ComplexExpand[
(Derivative[0, 1][fRe][x, t] + I Derivative[0, 1][fIm][x, t]) ==
(fRe[x, t] + I fIm[x, t])^2 Abs[Derivative[2, 0][fRe][x, t] + I Derivative[2, 0][fIm][x, t]],
TargetFunctions -> {Re, Im}] ;
Initial condition :
Plot[Evaluate@solAbs[x, 0], {x, -xrange, xrange}]
Boundary condition :
Plot[Evaluate@(solAbs[-xrange, t] - solAbs[xrange, t]), {t, 0, trange}, PlotRange -> All]