I have a PDE from my model's equation of motion(step.3) and I was suggested to use NDSolve to solve it, I was wondering how many boundary conditions(in step.4 and I currently had used 3 boundary conditions) I would need in order to successfully solve this PDE and produce a time evolution simulation(step.5) using the result produced with 'ndsolve'? And why? (And if I made a mistake somewhere since my code seems to produce an invariant straight line?). Thank you for reading my question!

(*Step1.Define and plot the field*)
lhs = 24
rhs = 40
beta = 0
field = -2/(1 + Exp[-x + rhs]) + 2/(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] == 0.9, D[y[t, 0], x] == 0, 
   D[y[t, 64], x] == 0}, y[t, x], {t, 0, 1}, {x, 0, 64}]

(*Step5.plot the field in spatial dimension at different times*)
nsol2 = nsol[[1, 1, 2]]
nsol3[t_, x_] = nsol2;
 Table[Plot[nsol3[t, x], {x, 0, 64}, PlotLabel -> t, 
   PlotRange -> {-1.5, 1.5}], {t, 0, 1, 0.01}]]
  • $\begingroup$ You're getting an invariant straight line because NDSolve is throwing an error and returning the input unevaluated, and you're then picking out part [[1,1,2]] of the original input (which happens to be 0.) As to how to fix it, I'm writing up something now. $\endgroup$ Feb 28, 2022 at 15:28

1 Answer 1


There are two problems in your code, one conceptual and one syntactical.

  • An initial value problem that is second-order in time derivatives needs two initial conditions (just as a second-order ODE in classical mechanics needs both an initial position and an initial velocity to uniquely specify a solution.) So you need to provide both $y(0,x)$ and $\dot{y}(0,x)$ to NDSolve.

  • The expression D[y[t, 0], x] returns 0, since y[t,0] does not literally depend on x. To get the quantity $\partial y/\partial x|_{x=0}$, use (D[y[t, x], x] /. x -> 0); this takes the derivative of y[t,x] with respect to x and then sets x to 0.

So replace your Step 4 with:

nsol = NDSolve[{pde, 
                y[0, x] == 0.9, 
                (D[y[t, x], t] /. t -> 0) == 0, (* or whatever IC you want *)
                (D[y[t, x], x] /. x -> 0) == 0, 
                (D[y[t, x], x] /. x -> 64) == 0}, 
               y[t, x], {t, 0, 1}, {x, 0, 64}]

and it works fine, returning a solution for y that doesn't depend on x but does depend on t. This makes sense, since if you impose homogeneous Neumann boundary conditions on your equation, then solutions of the form $y(x,t) = f(t)$ are allowed.

  • $\begingroup$ Also, note that your potential is not a "double well" but is instead a "double hump" given the signs you've put in your code. This may or may not have been your intention. $\endgroup$ Feb 28, 2022 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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