2
$\begingroup$

I'm trying to solve a PDE and plot the solution.

eqn = D[u[x, t], t] + u[x, t]*D[u[x, t], x] == 0;
cond1 = u[0, t] == 0;
cond2 = u[x, 0] == Min[x, 1];
sol = NDSolveValue[{eqn, cond1, cond2}, u[x, t], {x, 0, 3}, {t, 0, 3}];
Plot3D[sol, {x, 0, 3}, {t, 0, 3}]

However, the plot is empty and it shows the following errors:

Power::infy: Infinite expression 1/0. encountered.

Infinity::indet: Indeterminate expression 0. ComplexInfinity encountered.

NDSolveValue::ndnum: Encountered non-numerical value for a derivative at x == 0.

NDSolveValue::dsvar: 0.00021449999999999998` cannot be used as a variable.

Is there a way to fix this. I'm trying to tackle the following problem:

Mathematica solving pde  with NDSolveValue having two conditions and min function

$\endgroup$
5
$\begingroup$

NDSolve may be dividing by u[x,t] before working on the equation and u is 0 at x = 0. Moving to DSolve instead.

eqn = D[u[x, t], t] + u[x, t]*D[u[x, t], x] == 0;

cond1 = u[0, t] == 0
cond2 = u[x, 0] == Min[x, 1]

First use DSolve without conditions.

DSolve[eqn, u[x, t], {x, t}]
(* Solve[u[x, t] == C[1][x - t*u[x, t]], u[x, t]] *)

In the result C[1] is an arbitrary function rather than a constant. Look at the equation inside the solve expression. and change C[1] to F for clarity.

eq = u[x, t] == F[x - t*u[x, t]]

eq /. t -> 0
(* u[x, 0] == F[x] *)

which from cond2 gives us

F[x_] = Min[x, 1]

eq /. x -> 0
(* u[0, t] == Min[1, (-t)*u[0, t]] *)

From cond1, this equation is automatically satisfied.

eq
(* u[x, t] == Min[1, x - t*u[x, t]] *)

$Assumptions = x > 0 && t > 0

Solve[eq, u[x, t]] // Simplify

{{u[x, t] -> ConditionalExpression[1, t + 1 < x]}, 
  {u[x, t] -> ConditionalExpression[x/(t + 1), t + 1 > x]}}

Convert the above to piecewise for evaluation and using both conditions.

u[x_, t_] = Piecewise[{{1, t + 1 < x}, {x/(t + 1), t + 1 > x}}]

To show it solves original pde

eqn // Simplify
(* True *)

And Animate a plot.

gifs = Table[
   Plot[Evaluate[u[x, t]], {x, 0, 5}, PlotRange -> {0, 1}, 
    PlotLabel -> t "t"], {t, 0, 10, .05}];
ListAnimate[gifs]

enter image description here

Plot3D[Evaluate[u[x, t]], {x, 0, 5}, {t, 0, 5}]

works too.

Update

I got your code to work with one small change in cond1

cond1 = u[0, t] == 1/10000000;

or it could be any small non-zero value. It looks like NDSolve is dividing the pde by u to get du/dx at x = 0 with the predictable failure. The flat part of the plot is a little wavy, probably due to the abrupt change in slope causing some instability in the numerical solution.

$\endgroup$

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.