# Numerical solution of the hyperbolic equation

I am trying to solve the following hyperbolic equation with given boundary conditions: I choose as initial condition $$u=1$$, and evolve the above hyperbolic equation until reaching a stationary state with some predetermined tolerance.

Spatial derivatives are approximated by taking standard centered differences everywhere.

The Mathematica input is:

φ[z] = q*(1/z + (-1*q)/(-1*z));
η[z] := k* (1/z + (-1*q)/(-1*z));
r[ρ, z] := sqrt[ρ^2 + z^2];

NDSolve[ {Derivative[u[t, ρ, z], {t, 2}] ==
Derivative[u[t, ρ, z], {ρ, 2}] + (1/ρ)*
Derivative[u[t, ρ, z], {ρ, 1}] +
Derivative[
u[t, ρ, z], {z, 2}] - ((φ[z]^4)/4)* (
Derivative[(η[z] + u[t, ρ, z]  - 1)/φ[
z], {ρ,
1}] Derivative[(η[z] + u[t, ρ, z]  +
1)/φ[z], {ρ, 1}] +
Derivative[(η[z] + u[t, ρ, z]  - 1)/φ[
z], {z,
1}] Derivative[(η[z] + u[t, ρ, z]  +
1)/φ[z], {z, 1}]) *((η[z] +
u[t, ρ,
z])*((η[z] + u[t, ρ, z])^2 - (φ[z]^2)/
2) )^(-1), u[0, ρ, z] = 0, u[t, 6, z] = 1,
u[t, ρ, -6] = u[t, ρ, 6]},
u[t, ρ, z], {t, 0, 10}, {ρ, 0, 6}, {z, -6, 6},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"DifferenceOrder" -> "Pseudospectral"}}]


which gives errors.

I would like to ask if you could help me to solve this problem.

• Irina, could you please retype Mathematica's input in a form one could copy to notebook? Jul 7, 2014 at 22:05
• Gregory Rut, I'm new at this website, and couldn't find a way to appropriate form. I'll be glad if you make changes for any convenience. Jul 7, 2014 at 22:51
• @Irina, copy the code directly from the notebook and paste it into the edit window. Then select the code and press the code button, which looks like two braces, {}, above the edit window. Jul 8, 2014 at 3:12
• And don't TeX \$ on the code. Jul 8, 2014 at 3:20
• @Michael E2, thanks for the tip. Now, please, can someone help me to handle this problem? Jul 8, 2014 at 12:39

Comment: I think you want D instead of Derivative. Also == instead of =. And you probably want the functions defined with patterns z_ etc. But there are errors that you'll have to address. (Or perhaps someone else.)

ClearAll[φ, η, r, u];
φ[z_] = q*(1/z + (-1*q)/(-1*z));
η[z_] := k*(1/z + (-1*q)/(-1*z));
r[ρ_, z_] := Sqrt[ρ^2 + z^2];

pde = D[u[t, ρ, z], {t, 2}] ==
D[u[t, ρ, z], {ρ, 2}] + (1/ρ)*D[u[t, ρ, z], {ρ, 1}] +
D[u[t, ρ, z], {z, 2}] - ((φ[z]^4)/4)*
(D[(η[z] + u[t, ρ, z] - 1)/φ[z], {ρ, 1}] D[(η[z] + u[t, ρ, z] + 1)/φ[z], {ρ, 1}] +
D[(η[z] + u[t, ρ, z] - 1)/φ[z], {z, 1}] D[(η[z] + u[t, ρ, z] + 1)/φ[z], {z, 1}])*
((η[z] + u[t, ρ, z])*((η[z] + u[t, ρ, z])^2 - (φ[z]^2)/2))^(-1);
bc = {u[0, ρ, z] == 0,
u[t, 0, z] == 1,
u[t, ρ, -6] == u[t, ρ, 6]};

NDSolve[{pde, bc},
u[t, ρ, z], {t, 0, 10}, {ρ, 0, 6}, {z, -6, 6},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"DifferenceOrder" -> "Pseudospectral"}}]


NDSolve::ivone: Boundary values may only be specified for one independent variable. Initial values may only be specified at one value of the other independent variable. >>

I'll leave this up for a while, but I'll probably delete it since it is not an answer. :( Unless I forget. Maybe someone else can use it.

Update

q and k have to be given numeric values for NDSolve to work. In NDSolve, ρ starts at 0 and there's a 1/ρ in the PDE, which will give you a 1/0 error (when the NDSolve finally works). There may be other such singularities to deal with, but this one was obvious.

Here NDSolve goes to work but gives the 1/0 error. The trick to get it to work is to give a complete IVP for t. The highest order derivative is two, so initial values for u and its t derivative have to be given. (I do not know if this is how you should fix your problem.)

q = 2; k = 1/10; (* random values)
bc = {u[0, ρ, z] == 0,
Derivative[1, 0, 0][u][0, ρ, z] == 1,
u[t, 0, z] == 1,
u[t, ρ, -6] == u[t, ρ, 6]};
NDSolve[{pde, bc},
u[t, ρ, z],
{t, 0, 10}, {ρ, 0, 6}, {z, -6, 6},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"DifferenceOrder" -> "Pseudospectral"}}]


At this point, I believe I am stuck. The problem, I believe, is now a mathematical/scientific one of what the appropriate boundary and initial conditions are. It is also possible that there is an error (typo) in the PDE.

If you need to vary q and k as parameters, consider using ParametricNDSolve. But the basic NDSolve problem should be fixed first.

Sorry I can't be more help.

• Maybe someone more familiar with the solver for PDEs can. In any case I think the way to go with these things is to start small and build up, not write a big piece of code and then start trying to weed out various syntax errors, only to encounter algorithmic errors.
– acl
Jul 8, 2014 at 12:54
• @Michael E2, thanks. I got the same error message and have no idea how to correct. Jul 8, 2014 at 12:55
• @Irina Sqrt instead of sqrt
– eldo
Jul 8, 2014 at 13:00