Message Boards Message Boards

GROUPS:

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

Posted 11 months ago
1198 Views
|
5 Replies
|
2 Total Likes
|

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:
5 Replies

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 11 months ago

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

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 11 months 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?

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.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract