Message Boards Message Boards

[✓] Plot3D and Plot results of DSolve and NDSolve?

GROUPS:

I have run into trouble with a Plot3D problem. My code is following:

eqn = D[u[x, t], t] ==  D[D[u[x, t], x], x];

ic = {u[x, 0] == 1, u[0, t] == 0, Derivative[1, 0][u][10, t] == 0};

dsol = DSolve[{eqn, ic}, u, {x, t}];

Plot3D[u[x, t], {x, 0, 100}, {t, 0, 100}, ColorFunction -> "RustTones", Mesh -> All];

and the same problem happens in another Plot code:

linearsystem = {x'[t] == -3 x[t] + 2 y[t], y'[t] == x[t] - 4 y[t]};

initialvalues = {x[0] == 1, y[0] == 3};

sol2 = NDSolve[Join[linearsystem, initialvalues], {x, y}, {t, 0, 3}];

Plot[{x[t], y[t]}, {t, 0, 3}];

When I click "shift+return", it just results in an empty graph in both of these two codes. I don't know what is wrong with my code. Could anyone help me?

Attachments:
POSTED BY: Tim Zhang
Answer
15 days ago

Using the output of DSolve for plotting is not straightforward and you should really look up the documentation:

linearsystem = {x'[t] == -3 x[t] + 2 y[t], y'[t] == x[t] - 4 y[t]};
initialvalues = {x[0] == 1, y[0] == 3};
{sol2, sol3} = 
 NDSolveValue[Join[linearsystem, initialvalues], {x, y}, {t, 0, 3}]
Plot[{sol2[t], sol3[t]}, {t, 0, 3}]
POSTED BY: Gianluca Gorni
Answer
15 days ago

yes, good suggestion. Thank you very much. How about the problem in Plot3D? It still can just show the empty graph.

POSTED BY: Tim Zhang
Answer
14 days ago

The result from the PDE looks problematic to me. You give initial data with a discontinuity. The output contains an Inactive[Sum] which does not activate automatically. If I Activate it manually, it gives errors. So I take an approximant and see what happens:

eqn = D[u[x, t], t] == D[D[u[x, t], x], x];
ic = {u[x, 0] == 1, u[0, t] == 0, Derivative[1, 0][u][10, t] == 0};
dsol = DSolveValue[{eqn, ic}, u, {x, t}]
dsol2 = Activate[dsol /. Infinity -> 10]
Plot3D[dsol2[x, t], {x, 0, 100}, {t, 0, 100}]

I don't know if the result makes sense for your problem. It seems periodic in x.

POSTED BY: Gianluca Gorni
Answer
14 days ago

Thank you very much. It works. Also, I got another error when I want to find the numerical solution for this PDE. It says "Boundary condition is not specified on a single edge of the boundary of the computational domain." the code is following:

eqn = D[u[x, t], t] == D[D[u[x, t], x], x]

ic = {u[x, 0] == 1, u[0, t] == 0, Derivative[1, 0][u][10, t] == 0}

dsol2 = NDSolveValue[{eqn, ic}, u[x, t], {x, 0, 100}, {t, 0, 100}]

could you give me some hint to solve it?

POSTED BY: Tim Zhang
Answer
12 days ago

Sorry, I know almost nothing about PDEs. The messages in the following reformulation are perhaps more meaningful:

eqn = D[u[x, t], t] == D[D[u[x, t], x], x]
ic = {u[x, 0] == 1, u[0, t] == 0, Derivative[1, 0][u][10, t] == 0}
dsol2 = NDSolveValue[{eqn, ic}, u[x, t], 
  Element[{x, t}, Rectangle[{0, 0}, {100, 100}]]]

Try writing an explicit DirichletCondition.

POSTED BY: Gianluca Gorni
Answer
12 days ago

Group Abstract Group Abstract