Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question is a continuation of this.

As answered by J.M., I am able to iterate a solution. However, I am unable to plot it. I am sure that this has to do with my inability to understand how the plot routine works and I can't seem to figure it out:

state = First[
  NDSolve`ProcessEquations[{D[u[t, x], t] == D[u[t, x], x, x], 
    u[0, x] == 0, u[t, 0] == Sin[t], u[t, 5] == 0}, u, t, {x, 0, 5}]]

NDSolve`Iterate[state, 5]
NDSolve`ProcessSolutions[state, "Forward"]

Plot3D[
 Evaluate[u[t, x] /. NDSolve`ProcessSolutions[state, "Forward"]],
 {t,0,2},
 {x, 0, 5}
 ]

gives me a blank plot with no curves. What am I doing wrong? I can't omit {t, 0, 2} as that would give me an error.

share|improve this question
    
have a look at this: reference.wolfram.com/mathematica/tutorial/… –  acl May 22 '12 at 15:23
    
@acl I did have a look at that. When I replaced the u[t,x,y] equation with u[t,x], all I got was blank plots. –  drN May 22 '12 at 15:24
add comment

2 Answers 2

If you look at the interpolation object that's returned, it's not a function u(t,x) only u(x) with fixed t. In fact, it returns both u[x] and u'[x] for fixed t. So try

state = First[
NDSolve`ProcessEquations[{D[u[t, x], t] == D[u[t, x], x, x], 
u[0, x] == 0, u[t, 0] == Sin[t], u[t, 5] == 0}, u, t, {x, 0, 5}]]

Table[NDSolve`Iterate[state, t];
Plot[NDSolve`ProcessSolutions[state, "Forward"][[All, 2]], {x, 0, 5},
PlotRange -> 1], {t, 0, 5}]

enter image description here

share|improve this answer
    
Thanks for making the distinction between u[t,x] and u[x]. It wasn't obvious to me! :) –  drN May 23 '12 at 14:35
add comment

Something like this?

L = -10;
state = First[
   NDSolve`ProcessEquations[{D[u[t, x], 
       t] == + D[u[t, x], x, x] - Sin[u[t, x]],
     u[0, x] == Exp[-(x^2)],
     u[t, -L] == u[t, L]}, u, t, {x, -L, L}, 
    Method -> {"MethodOfLines", 
      "SpatialDiscretization" -> {"TensorProductGrid", 
        "DifferenceOrder" -> "Pseudospectral"}}]];
GraphicsGrid[Partition[Table[
   NDSolve`Iterate[state, tau ];

   Plot[Evaluate[
     u[tau, x] /. 
      NDSolve`ProcessSolutions[state, "Forward"]], {x, -L, L}, 
    PlotRange -> {-1/4, 1/4}],
   {tau, 0., 3., .5}], 2]]

Mathematica graphics

share|improve this answer
    
You know, I'll have to check my [ and see if all is well with my code. –  drN May 22 '12 at 15:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.