0
$\begingroup$

I am trying to define a function for future NDSolve use

oweqn = (1/(c)^2) D[y[t, x], {t, 2}] - D[y[t, x], {x, 2}] + k1 y[t, x] = 0

Where I predefined $c$ to be a given function of $x$. Everything works perfectly until I entered the above code with which mathematica returned:

Set::write: Tag Plus in y[t,x]-(y^(0,2))[t,x]+(1+2 Sech[x]^2) (y^(2,0))[t,x] is Protected.

I could not see which character in my code is in conflict with predefined mathematica character.

$\endgroup$
3
  • 2
    $\begingroup$ try changing the end = 0 to ==0 and see if fixes it. $\endgroup$
    – Nasser
    Oct 24, 2021 at 21:18
  • 3
    $\begingroup$ Use FullForm to see what your expression really looks like. In fact, you do the assignment Plus[...]=0 instead of building an equation Plus[...]==0. Clearly, one cannot assign a zero to the Plus tag. $\endgroup$
    – yarchik
    Oct 24, 2021 at 21:29
  • $\begingroup$ See mathematica.stackexchange.com/questions/11982/… $\endgroup$
    – Michael E2
    Oct 24, 2021 at 21:59

1 Answer 1

3
$\begingroup$

Here's a slight modification of Mr. Wizard's findBadSets that highlights the protected tag with Inactive and the erroneous Set in red:

ClearAll[findBadSets];
SetAttributes[findBadSets, HoldFirst]

findBadSets[expr_] := 
 Cases[Unevaluated@
    expr, (h : Set | SetDelayed)[bad : head_Symbol[___], val_] /; 
     MemberQ[Attributes@head, Protected] :> 
    With[{set = Style[HoldForm@h["", ""], Red],
      badh = Map[InputForm, Inactive[head] @@@ HoldForm@bad, {2}]},
     HoldForm[Row[{head, Spacer[50], badh, set, InputForm@val}]]
     ], -1] // Column

findBadSets[
 oweqn = (1/(c)^2) D[y[t, x], {t, 2}] - D[y[t, x], {x, 2}] + 
    k1 y[t, x] = 0
 ]

Mathematica graphics

$\endgroup$

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