Suppose I have a Module in which I use Solve[]. If I make the solve variable local,
I get this:
f[a_] := Module[{soln, x},
soln = Solve[2 x == a, {x}];
Return[soln]
];
f[5]
(*{{x$117834 -> 5/2}}*)
If instead I leave the solve variable global, I get this cleaner result:
g[a_] := Module[{soln},
soln = Solve[2 x == a, {x}];
Return[soln]
];
g[5]
(*{{x -> 5/2}}*)
But if globally x has a value, x=7, this fails:
(*7 is not a valid variable*)
Why does the local variable x in the first example become x$117834? What is the
best way to use variables like x in this circumstance?
xalong withato the module to avoid all these issues. That would be the safest method. See using-solve-in-module as an example. – Nasser Mar 31 '20 at 21:34