# “Tag times protected” for this doesn't make sense

I have a property calculator which is in a Table to generate well... a table of properties and growth rates depending on the value of d. The growth rate omega and qmax are functions of d.

Clear[h, \[Delta], A1, D1, S1, M1, P1, G1, m, E1, \[Lambda]max, qmax,
K1, d];

Table[
(*d=2.350*10^-3;*)
{
\[Rho] = 1333;
MW = 84.6;
Rg = 8.314;
\[Sigma] = 0.0295;
\[Sigma]T = 2.148*10^-4;
Ts = 300;
\[CapitalDelta]T = 10;
\[Nu] = 3.477*10^-7;
Cp = 1.18*10^3;
k = 0.14;
\[Chi] = k/(\[Rho] Cp);
\[Beta] = 10^-3;
\[Alpha] = 1.0;
xg = 0;
g = 9.81;
{
{L1 = 350*10^3;},
{G1 = xg g d^3/(\[Nu] \[Chi]);}
}
S1 = (\[Sigma] d)/(3 \[Rho] \[Nu]^2);
M1 = \[Sigma]T \[CapitalDelta]T d/(\[Rho] \[Nu] \[Chi]);
Bo = xg G1/S1;
K1 = 1;
B = 0.0;
Bi = 1 + B K;
P1 = \[Nu]/\[Chi];

A1 = 1.987*10^-11;
a = A1/S1;
m = (M1 K1 Bi)/(2 P1 S1);
E1 = k \[CapitalDelta]T/(\[Rho] \[Nu] L1);
D1 = 0.001;
\[Epsilon] = E1/S1;
\[Delta] = E1^2/(D1 S1);
qmax[Bo_, d_] :=
Sqrt[(a d^-1 - Bo d^3 + \[Delta] d^3 (Bi d + K1)^-3 +
m d^2 (Bi d + K1)^-2)/(2 (d^3))];
ScientificForm[
Re[Bi \[Epsilon]/((Bi d + K1)^2) - d^3 q^4 - Bo d^2 q^2 +
m q^2 d^2/((Bi d + K1)^2) + \[Delta] d^3 q^2/((Bi d +
K1)^3) /. {q -> qmax[Bo, 1]^2}]]},
{d, 0.0001, 0.005}
]


However, I get the following error.

Set::write: Tag Times in S1 {{Null},{Null}} is Protected. >>

Without the Table function, it runs fine:

Clear[h,\[Delta],A1,D1,S1,M1,P1,G1,m,E1,\[Lambda]max,qmax,K1,d];
\[Rho]=1333;
MW=84.6;
Rg=8.314;
\[Sigma]=0.0295;
\[Sigma]T=2.148*10^-4;
Ts=300;
\[CapitalDelta]T=10;
\[Nu]=3.477*10^-7;
Cp=1.18*10^3;
k=0.14;
\[Chi]=k/(\[Rho] Cp);
\[Beta]=10^-3;
\[Alpha]=1.0;
xg=0;
g=9.81;
L1=350*10^3;
G1=xg g d^3/(\[Nu] \[Chi]);

S1=(\[Sigma] d)/(3 \[Rho] \[Nu]^2);
M1=\[Sigma]T \[CapitalDelta]T d/(\[Rho] \[Nu] \[Chi]);
Bo=xg G1/S1;
K1=1;
B=0.0;
Bi=1+B K;
P1=\[Nu]/\[Chi];

A1=1.987*10^-11;
a=A1/S1;
m=(M1 K1 Bi)/(2 P1 S1);
E1=k \[CapitalDelta]T/(\[Rho] \[Nu] L1);
D1=0.001;
\[Epsilon]=E1/S1;
\[Delta]=E1^2/(D1 S1);
qmax[Bo_,d_]:=Sqrt[(a d^-1 -Bo d^3+\[Delta] d^3 (Bi d+K1)^-3+m d^2 (Bi d+K1)^-2)/(2 (d^3))];
ScientificForm[
Re[Bi \[Epsilon]/((Bi d+K1)^2)-d^3 q^4-Bo d^2 q^2+m q^2 d^2/((Bi d+K1)^2)+\[Delta] d^3 q^2/((Bi d+K1)^3)/.{q->qmax[Bo,1]^2}]]


Obviously this means that I don't have some = set correctly. I've been at it for hours and can't seem to detect anything wrong. Perhaps someone on here can?

The thing that bothers me is the code is staggered and I didn't do that....

-

It seems that this answer is proving popular. Let me take my suggestion to the next level.

Here is a function findBadSets that will find any explicitly bad Set/SetDelayed attempts in a given expression. Simply wrap it around a syntactically complete block of code, or follow the block with // findBadSets and the errors are printed one per row, protected symbol followed by complete left-hand side for each bad Set:

(* rest of code *) . . . {q -> qmax[Bo, 1]^2}]]}, {d, 0.0001, 0.005}] // findBadSets


Code for function:

SetAttributes[findBadSets, HoldFirst]

Cases[
Unevaluated @ expr,
/; MemberQ[Attributes@head, Protected] :>
-1] // Column


You are missing a semicolon in this line before S1:

{{L1 = 350*10^3;}, {G1=xg g d^3/(ν χ);}} S1=(σ d)/(3 ρ ν^2);


For finding this kind of problem you might use this approach. Put your entire expression inside a Hold and set expr = Hold[ (* your expression *) ], then:

Cases[expr, (Set | SetDelayed)[bad : HoldPattern[Times]@___, _] :> HoldForm[bad], -1]


This gives you the left-hand side of any = or := which is attempting an assignment to head Times.
You could also replace Times with any other head that you get in a Set::write message.

-
I just caught that. However, without the semicoln, a table of results isn't generated.... I was expecting a table with all values for {d,0.0001, 0.0005} – drN Oct 12 '12 at 19:49
Erm... I am thinking of deleting this question. A stroll in the cold really opened up my eyes to the idiocy of it. – drN Oct 12 '12 at 19:55
@drN well, I tried to extend my answer to make it useful for others having a similar problem rather than this one typo alone. – Mr.Wizard Oct 12 '12 at 19:58
@MrWizard thank you! – drN Oct 12 '12 at 20:02
@MrWizard Why doesn't having a ListPlot around the Table work? All I get is a blank plot even though I prescribe the PlotRange->{{0,0.0005},{0, 5*10^-5}}. Unless PlotRange isn't a property of ListPlot.... – drN Oct 12 '12 at 20:06
show 4 more comments