# Yet another error of "Your post appears to contain code that is not properly formatted as code"

I feel like I've found and read through all the relevant posts on Meta about this error, but I still can't resolve this error! I have about 6 equations in double-dollar-signs, several in single-dollar-sign, 4 large code blocks, 2 links, and a bunch of text. I have not been able to narrow down the location of the error by systematically removing sections of the question, so it seems that the error is happening in many locations. It is more than 100 lines long, so if I could attach it as a file or something, that would help (though it appears that I can't). How else can I share the text for my question without throwing the error here?

The (updated) text is added below. I am posting on the Mathematica SE site.

Assuming $A$ is a $3 \times 3$ matrix (and a function of $x$, and $z$) and $K_i, \beta_i$, and $\alpha(T)$ are known parameters, I need to solve the following equation, (with an implied sum over $\mu, i$, and $j$),

$K_1 \partial^2_j A_{\mu i} + K_{23} \partial_i (\partial_j A_{\mu j}) = 2\beta_1 Tr(A A^T) A^*_{\mu i} + 2\beta_2 Tr(A A^\dagger) A_{\mu i} + 2 \beta_3 [A A^T A^*]_{\mu i} + 2 \beta_4 [A A^\dagger A]_{\mu i} + 2 \beta_5 [A^* A^T A]_{\mu i} + \alpha(T) Tr(A A^\dagger)$

This system of equations can be simplified with a known form of $A$. For example,

$A = \begin{pmatrix} A_{xx} & 0 & 0 \\ 0 & A_{yy} & 0 \\ 0 & 0 & A_{zz} \end{pmatrix}$

the equations reduce to (when normalized),

$a_{||}'' = -\frac{1}{5} a_{||} ( 2 a_{||}^2 + a_\perp^2 ) + \frac{2}{5} a_{||} ( 2 |a_{||}|^2 + |a_\perp|^2 ) + \frac{2}{5} |a_{||}|^2 a_{||} - a_{||}$

and

$3 a_\perp'' = -\frac{1}{5} a_\perp^* ( 2 a_{||}^2 + a_\perp^2 ) + \frac{2}{5} a_\perp ( 2 |a_{||}|^2 + |a_\perp|^2 ) + \frac{2}{5} |a_\perp|^2 a_\perp - a_\perp$

These appear rather simple, and I figured that Mathematica could solve them with NDSolve, but it hasn't worked. With more complicated forms of $A$ and more complicated regions, I'm looking to use Mathematica's FEM solver, but I just don't understand how to build the derivative matrix. I've looked at [Wolfram's PDE solving guide][3] and their [FEM guide][1], but I only see coefficients for gradients, divergences, etc., while I will also need mixed derivatives ($\partial_i (\partial_j A_{\mu j})$). How do I build the mixed derivative matrix in InitializePDECoefficients? I have some working code in C++ that using the finite difference method, and I build the matrices there, but shouldn't there be a better way than inserting every element? [Here][2] it seems that the matrices were large, but Mathematica documentation [here][1], they use a $2 \times 2$ identity matrix, but for the coefficient? I'm a little confused there.

Or, how can I get NDSolve or NDSolveValue to work? The boundary conditions seem to be causing problems in these functions. The BC's for my equations are, (for the first BC, I just assume that zMax (in code below) is close enough to infinity.)

$\partial_z A_{\alpha j}|_{z=0} = \frac{1}{b}A_{\alpha j}|_{z=0}, \text{ for } b \in [0,\infty)$

and

$\lim_{z \to \infty} A_{\alpha j} = 1.$

My code so far (using NDSolve first),

b = 1;
{xMin, xMax} = {-5, 5};
{zMin, zMax} = {0, 20};
sol = NDSolve[
{D[p[x, z], {z, 2}] == -(1/5) (2 p[x, z]^2 + s[x, z]) Conjugate[p[x, z]] + 2/5 (2 Abs[p[x, z]]^2 + Abs[s[x, z]]^2) p[x, z] + 2/5 Abs[p[x, z]]^2 p[x, z] - p[x, z],
3 D[s[x, z], {z, 2}] == -(1/5) (2 p[x, z]^2 + s[x, z]) Conjugate[s[x, z]] + 2/5 (2 Abs[p[x, z]]^2 + Abs[s[x, z]]^2) s[x, z] + 2/5 Abs[s[x, z]]^2 s[x, z] - s[x, z],
(D[s[x, z], z] /. {z -> zMin}) == 1/b s[x, zMin],
s[x, zMax] == 1,
p[x, zMax] == 1,
(D[p[x, z], z] /. {z -> zMin}) == 0 },
{p, s}, {x, xMin, xMax}, {z, zMin, zMax}
]

This code gives the same error twice (I thought I had other errors previously, but I can't seem to recreate them).

> NDSolve: The expression s^(0,1)[x, 0] == s given as a spatial boundary condition for the possibly automatically chosen finite element method should not have explicit derivatives of the dependent variables. NeumannValue should be used to specify spatial derivatives at the boundary.

And my other attempt,

Needs["NDSolve'FEM'"] (* single quote here is actually a backtick *)
b = 1;
{xMin, xMax} = {-5, 5};
{zMin, zMax} = {0, 20};
nRegion = ToNumericalRegion[Rectangle[{xMin, zMin}, {xMax, zMax}]];

\[CapitalGamma]pi = NeumannValue[0, z == 0];
\[CapitalGamma]pf = DirichletCondition[p[x, z] == 1, z == zMax];
\[CapitalGamma]si = NeumannValue[s[x, z]/b, z == 0];
\[CapitalGamma]sf = DirichletCondition[s[x, z] == 1, z == zMax];

eqP = -D[p[x, z], {z, 2}] == -(1/5) (2 p[x, z]^2 + s[x, z]) Conjugate[p[x, z]] + 2/5 (2 Abs[p[x, z]]^2 + Abs[s[x, z]]^2) p[x, z] + 2/5 Abs[p[x, z]]^2 p[x, z] - p[x, z];

eqS = -3 D[s[x, z], {z, 2}] == -(1/5) (2 p[x, z]^2 + s[x, z]) Conjugate[s[x, z]] + 2/5 (2 Abs[p[x, z]]^2 + Abs[s[x, z]]^2) s[x, z] + 2/5 Abs[s[x, z]]^2 s[x, z] - s[x, z];

sol = NDSolveValue[{{eqP == \[CapitalGamma]pi, \[CapitalGamma]pf}, \{eqS == \[CapitalGamma]si, \[CapitalGamma]sf}}, {p, s}, {x, z} \[Element] nRegion]

gives these errors, twice:

> DiscretizePDE: The FEMStiffnessElements operator failed.
>
> FindRoot: The minimal damping factor of 1/10000 has been reached.
>
> FindRoot: The step size in the search has become less than the tolerance prescribed by the PrecisionGoal option, but the function value is still greater than the tolerance prescribed by the AccuracyGoal option.
>
> NDSolveValue: PDESolve could not find a solution.

[1]:
https://reference.wolfram.com/language/FEMDocumentation/tutorial/FiniteElementProgramming.html
[2]:
https://mathematica.stackexchange.com/questions/173677/how-to-find-the-differentiation-matrix-based-on-fem
[3]:
https://reference.wolfram.com/language/FEMDocumentation/tutorial/SolvingPDEwithFEM.html

• You can edit your question, add a code fence (three backticks at the start of a new blank line) then your content that won't post and end with three backticks again at the end on a new single line. Please include on which site you're trying to post Some sites have extra script / Mathjax options that can cause new issues in remarkable ways.
– rene
Commented Dec 29, 2021 at 18:03
• Can you replace  with \$? It helped someone else. Commented Dec 29, 2021 at 19:23
• @Laurel, thank you for the idea; sadly, it wasn't successful. I looked at the post and comments in the link...would it be better that I put this question on the Mathematica SE Meta site? Also, I saw a comment somewhere saying that the Meta sites describe what Mathjax and special characters are allowed and how to use them, but I can't find anything on Mathematica SE Meta. Commented Dec 30, 2021 at 1:49
• @rene, thank you for the suggestion; I have adjusted the text. Commented Dec 30, 2021 at 1:54
• You can't ask on their meta unless you have 5 reputation on their site. I still have to wonder if the Mathjax is somehow responsible, but I'd have to look for some other question that might have more details. Commented Dec 30, 2021 at 2:04
• I'll just use a simple work-around for now, using github. Commented Dec 31, 2021 at 5:00
• Another user edited my problematic question and pasted the text (since they had enough rep), so it "fixed." Thanks for all the help. Commented Dec 31, 2021 at 17:06

It is not clear what the conditions are that trigger this message. This post indicates that the idea stems from a suggestion in another post, which lists some proposed triggers. You might consider whether any of those might be the cause in your post. A quick glance through your post suggests that perhaps something like C++ could fall into the "uncommon characters/operators" category, or the (correct) use of semicolons between phrases (though they aren't at the end of a line), or the dots in matrix...for, or even 2x2. Try putting spaces around the ellipses and the x, and maybe put C++ in backtics.