# Is always possible to define a numerical value using subscript?

In this code I defined some values using subscripts and it is not the first time I did this but strangely the code execution crashes. To follow the code.

   Subscript[\[Gamma], 1] = 6000;
Subscript[\[Gamma], Subscript[H, 2] O] = 9810;
Subscript[p, M] = 0.038*9.81/10^-2;
s = {Subscript[p, A], Subscript[p, B], Subscript[p, C]} /.
Solve[{Subscript[p, C]/Subscript[\[Gamma], 1] ==
Subscript[p, M]/Subscript[\[Gamma], 1] - 5,
Subscript[p, B]/Subscript[\[Gamma], 1] ==
Subscript[p, M]/Subscript[\[Gamma], 1] + 1,
Subscript[p, A]/Subscript[\[Gamma], Subscript[H, 2] O] ==
Subscript[p, B]/Subscript[\[Gamma], Subscript[H, 2] O] +
6}, {Subscript[p, A], Subscript[p, B], Subscript[p, C]}];
Subscript[p, A] = Extract[Extract[s, 1], 1];
Subscript[p, B] = Extract[Extract[s, 1], 2];
Subscript[p, C] = Extract[Extract[s, 1], 3];
A = {Subscript[p, A]/Subscript[\[Gamma], Subscript[H, 2] O], 0};
B = {Subscript[p, B]/Subscript[\[Gamma], Subscript[H, 2] O], 6};
C = {Subscript[p, C]/Subscript[\[Gamma], Subscript[H, 2] O], 12};
Graphics[Line[{A, B, C}], Axes -> True]


So where is the mistake? Pheraps is not always possible to define a numerical value using subscript?

• Comments are not for extended discussion; this conversation has been moved to chat.
– Kuba
Commented Nov 25, 2021 at 11:59

Using a fresh kernel:

Subscript[\[Gamma], 1] = 6000;
Subscript[\[Gamma], Subscript[H, 2] O] = 9810;
Subscript[p, M] = 0.038*9.81/10^-2;

s = {Subscript[p, A], Subscript[p, B], Subscript[p, C]} /.
Solve[{Subscript[p, C]/Subscript[\[Gamma], 1] ==
Subscript[p, M]/Subscript[\[Gamma], 1] - 5,
Subscript[p, B]/Subscript[\[Gamma], 1] ==
Subscript[p, M]/Subscript[\[Gamma], 1] + 1,
Subscript[p, A]/Subscript[\[Gamma], Subscript[H, 2] O] ==
Subscript[p, B]/Subscript[\[Gamma], Subscript[H, 2] O] +
6}, {Subscript[p, A], Subscript[p, B], Subscript[p, C]}]

Subscript[p, A] = Extract[Extract[s, 1], 1];
Subscript[p, B] = Extract[Extract[s, 1], 2];
Subscript[p, C] = Extract[Extract[s, 1], 3];
aa = {Subscript[p, A]/Subscript[\[Gamma], Subscript[H, 2] O], 0};
bb = {Subscript[p, A]/Subscript[\[Gamma], Subscript[H, 2] O], 6};
cc = {Subscript[p, C]/Subscript[\[Gamma], Subscript[H, 2] O], 12};
Graphics[Line[{aa, bb, cc}], Axes -> True]


EDIT using lowercase subscripts

Using a fresh kernel:

Subscript[\[Gamma], 1] = 6000;
Subscript[\[Gamma], Subscript[H, 2] O] = 9810;
Subscript[p, m] = 0.038*9.81/10^-2;

s = {Subscript[p, a], Subscript[p, b], Subscript[p, c]} /.
Solve[{Subscript[p, c]/Subscript[\[Gamma], 1] ==
Subscript[p, m]/Subscript[\[Gamma], 1] - 5,
Subscript[p, b]/Subscript[\[Gamma], 1] ==
Subscript[p, m]/Subscript[\[Gamma], 1] + 1,
Subscript[p, a]/Subscript[\[Gamma], Subscript[H, 2] O] ==
Subscript[p, b]/Subscript[\[Gamma], Subscript[H, 2] O] +
6}, {Subscript[p, a], Subscript[p, b], Subscript[p, c]}]

Subscript[p, a] = Extract[Extract[s, 1], 1];
Subscript[p, b] = Extract[Extract[s, 1], 2];
Subscript[p, c] = Extract[Extract[s, 1], 3];
aa = {Subscript[p, a]/Subscript[\[Gamma], Subscript[H, 2] O], 0};
bb = {Subscript[p, b]/Subscript[\[Gamma], Subscript[H, 2] O], 6};
cc = {Subscript[p, c]/Subscript[\[Gamma], Subscript[H, 2] O], 12};
Graphics[Line[{aa, bb, cc}], Axes -> True]


EDIT

The problem is that pA, PB etc are being used later on and you need to clear these before Solve. Starting with a fresh kernel the following can be evaluated any number of times. There are no subscripts, and no uppercase starting symbols either but you can experiment with variations yourself.

g1 = 6000;
gH20 = 9810;
pM = 0.038*9.81/10^-2;


Look at the color of the variables, that is a good sign that Solve recognizes these as variables.

Clear[s, pA, pB, pC];
s = {pA, pB, pC} /. First@Solve[{pC/g1 == pM/g1 - 5, pB/g1 ==
pM/g1 + 1, pA/gH20 == pB/gH20 + 6}, {pA, pB, pC}]

pA = s[[1]]
pB = s[[2]];
pC = s[[3]];
aa = {pA/gH20, 0};
bb = {pB/gH20, 6};
cc = {pC/gH20, 12};
Graphics[Line[{aa, bb, cc}], Axes -> True]


I have made minor improvements to avoid a double Extract. The picture doesn't change from the second one.