# how to animate a 2D plot evolution from the 3D plot (solved using NDSolve)?

I have the problem of trying to get 2D plot from a 3D plot (which used NDSolve to solve the PDE), and I need the 3D plot's x-axis and y-axis to be the axes for my 2D plot while the z-axis of it to be the time for my 2D plot. I wrote the following code:

(*Step1. Define and plot the field*)
lhs = 24
rhs = 40
beta = 0
field = 1/(1 + Exp[-x + rhs]) - 1/(1 + Exp[-x + lhs]) + 1 + beta   (*our field value v.s. spatial dimension*)
Plot[field, {x, 0, 64}, PlotRange -> {{0, 64}, {-1, 2}}]

(*Step.2 Define the field potential derivative dv/dphi*)
b = 0.1
dv = (y[t, x]^2 - 1)*(y[t, x] + b)       (*dv actually denotes dv/dphi*)

(*Step3. Define PDE from our E.O.M *)
pde = D[y[t, x], {t, 2}] - D[y[t, x], {x, 2}]+ dv == 0

(*Step4. Use NDSolve to solve PDE with the help of known initial condition - field value v.s. spatial coordinate at t0 *)
nsol = NDSolve[{pde, y[0, x] == field}, y[t, x], {t, 0, 10}, {x, 0, 64}]

(*Step5. plot the field in spatial dimension at different times*)
nsol2 = nsol[[1, 1, 2]]
Plot3D[nsol2, {t, 0.000, 0.001}, {x, 0, 64},
PlotRange -> {-1.5, 1.5}]
Plot3D[nsol2, {t, 0.200, 0.201}, {x, 0, 64},
PlotRange -> {-1.5, 1.5}]
Plot3D[nsol2, {t, 0.400, 0.401}, {x, 0, 64},
PlotRange -> {-1.5, 1.5}]
Plot3D[nsol2, {t, 0.600, 0.601}, {x, 0, 64},
PlotRange -> {-1.5, 1.5}]



where the horizontal axis(x-axis) denotes spatial coordinates, vertical axis(y-axis) denotes field value, inward axis(z-axis) denotes time.

What I need is to get an animation of 2D plot of y-axis versus x-axis over time, and I wrote the code to be 'Animate[Plot[nsol2, {x, 0, 64}, PlotRange -> {-1.5, 1.5}], {t, 0, 10}]' but it does not show any plot. Please let me know what could be the correct way to do this. Thank you for reading my post! • Mathematica v12.2 cann't solve the pde and gives message FindRoot::dfmin: The minimal damping factor of 1/10000 has been reached. and NDSolveValue::fempsf: PDESolve could not find a solution. What's your Mathematica version? Nov 11, 2021 at 10:28
• My version is Mathematica 12.0.0.0.(under MacOS Big Sur) I got the same message of 'FindRoot::dfmin: The minimal damping factor of 1/10000 has been reached.' when i directly copy and run my code above, but I do not have 'NDSolveValue::fempsf: PDESolve could not find a solution.' If you have the same version you should be able to get 5 plots in total, and the last 4 plots after manual rotation are the images above
– jack
Nov 11, 2021 at 11:07
• Unfortunately not, because nsol has no value! Nov 11, 2021 at 11:14
• May I ask how to deal with this error? I don't know why my Mathematica is able to produce graphical outcome with the codes above
– jack
Nov 11, 2021 at 11:23
• No idea. Can you reproduce your plots with a fresh kernel? Nov 11, 2021 at 11:35

Try

solution of pde:

Y = NDSolveValue[{pde, y[0, x] == field}, y, {t, 0,10}, {x, 0, 64}]


animation:


Module[{}, Animate[Plot[Y[t, x], {x, 0,64},PlotRange -> {-1.5, 1.5}],{t, 0, 10} ]] • yes it works well! thanks!
– jack
Nov 11, 2021 at 12:54

Maybe something like this

nsol3[t_, x_] = nsol2;
ListAnimate[ Table[Plot[nsol3[t, x], {x, 0, 64}, PlotLabel -> t,
PlotRange -> {-1.5, 1.5}], {t, 0, 10,0.1}]] • thanks i tested and this works well!
– jack
Nov 11, 2021 at 12:54