3

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?

praseodym
  • 2,134
  • 15
  • 29
Uri Merhav
  • 300
  • 2
  • 13

1 Answers1

3

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}] ;

equation

Initial condition :

Plot[Evaluate@solAbs[x, 0], {x, -xrange, xrange}]

IC

Boundary condition :

Plot[Evaluate@(solAbs[-xrange, t] - solAbs[xrange, t]), {t, 0, trange}, PlotRange -> All]

enter image description here

b.gatessucks
  • 1,242
  • 1
  • 15
  • 19
  • 1
    Thanks a lot for your reply. Do you have any idea why Mathematica fails without this explicit separation into real and imaginary parts? And also, in case someone else reads this later on: since my real expression is obviously much longer than that, changing the equation "by hand" to include an explicit real and imaginary part is not so attractive. A generic way to do this "explicit complexification" for any complex function f would be: f -> Function[{x,t} fre[x,t] + I fim[x,t]] – Uri Merhav Jan 12 '13 at 22:40
  • Also, in order to collect for Real and Imaginary equalities, I'd add: ComplexExpand [Thread[Im[equation], Equal]] ComplexExpand [Thread[Re[equation], Equal]]' – Uri Merhav Jan 12 '13 at 23:12