6
$\begingroup$

Please excuse me if the question has already been answered somewhere else, but I was not able to find it. Could somebody tell me what I am doing wrong here? The solution of DSolve is of course correct (u[t,x] = 5tx, u[1,10]/.sol = 50), but the one of NDSolve is going in the complete wrong direction (u[1,10]/.soln = -50). Why??? Do you get the same values when you run the code? Where did I write something wrong? This is really driving me nuts!

sol = DSolve[
{
 0 + D[u[t, x], {x, 2}] == 0
 , u[t, 0] == 0
 , (D[u[t, x], x] /. x -> 10) == 5*t
 }
, {u}
, {t, x}
][[1]];
u[1, 10] /. sol
(*50*)

soln = NDSolve[
{
 0 + D[u[t, x], {x, 2}] == 0
 , u[t, 0] == 0
 , (D[u[t, x], x] /. x -> 10) == 5*t
 }
, {u}
, {t, 0, 1}
, {x, 0, 10}
][[1]];
u[1, 10] /. soln
(*-50*)
$\endgroup$
  • 2
    $\begingroup$ I get the same result, looks like a bug to me, most probably in the relatively new FE code. It is just a suscpicion, but Method->"MethodOfLines" complains that it can't handle that case of boundary conditions (which I think is also reasonable) which only leaves Method->"FiniteElement". I'd report it to WRI. Probably just a simple sign problem as you can get what looks like the desired result when switching the sign in the boundary condition to -5*t :-) $\endgroup$ – Albert Retey May 11 '15 at 20:29
  • $\begingroup$ Looks like a bug to me too, but I'll let someone more knowledgeable confirm it. $\endgroup$ – Daniel Lichtblau May 11 '15 at 23:36
  • $\begingroup$ Plots of the two solutions in the Question clearly indicate the NSolve is returning 5 t x, and NDSolve is returning the numerical representation of -5 t x. Curiously, DSolveValue[{0 + D[u[t, x], {x, 2}] == 0, u[t, 0] == 0, (D[u[t, x], x] /. x -> 10) == 5*t}, {u}, {t, x}] under Mathematica 10.1 returns unevaluated. $\endgroup$ – bbgodfrey May 12 '15 at 0:48
  • $\begingroup$ By the way, one can work around this in NDSolve by making it into an explicit ODE. soln2[t_?NumericQ] := NDSolve[{D[u[x], {x, 2}] == 0, u[0] == 0, (D[u[x], x] /. x -> 10) == 5*t}, {u}, {x, 0, 10}]. My suspicion is that NDSolve is confusing itself in trying to handle an apparent PDE what really is only a DE in one variable. That's just a guess though. $\endgroup$ – Daniel Lichtblau May 13 '15 at 16:14
  • $\begingroup$ This problem still persists as of Version 10.1 $\endgroup$ – gwr May 20 '15 at 9:45
2
$\begingroup$

This is a NeumannValue and this can very subtle. There is a section NeumannValue and Formal Partial Differential Equations that tries to explain it.

Here is a way to do it:

soln = NDSolve[{D[u[t, x], {x, 2}] + NeumannValue[5 t, x == 10] == 0, 
     u[t, 0] == 0}, {u}, {t, 0, 1}, {x, 0, 10}][[1]];
u[1, 10] /. soln
50.00000000002088`
$\endgroup$
  • $\begingroup$ hmmm... ok. But in that case only conditions linear in the solution are treatable with NeumannValue according to the new FEM method, correct? Complicated nonlinear conditions on the gradients cannot be handled with this. I am not complaining about Mathematica or its FEM, I just want to see if I got this right. $\endgroup$ – Mauricio Fernández Oct 12 '15 at 13:35
  • $\begingroup$ Yes, that's correct. Non-linear boundary conditions are not handled in currently (V10.2). Sorry about that. $\endgroup$ – user21 Oct 12 '15 at 17:01
  • $\begingroup$ ok, thank you very much! $\endgroup$ – Mauricio Fernández Oct 13 '15 at 12:45

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.