3
$\begingroup$

Solving a function in more than one variable, Mathematica gives me output in this way:

name_variable$number

instead of giving me a number. I looked for symbol:

$

online, but unfortunately I can't find what it means.

--sorry for my English--


example - creating a function quadrilateral:

Q[q_, x1, y1_, l1_, l2_, l3_, l4_] :=
  Module[{x2, y2, x3, y3, x4, y4, theta1, theta2},
    x2 =x1 + l1 Cos[q];
    y2 =y1 + l1 Sin[q];
    (*others*) 
    {x2, y2, y3, x3, theta1, theta2}
  ]

p = Q[q, 0, 0, 3, 5, 2, 4, ...]

It gives me a Out like: {..., theta2**$**6657, ...} where 6657 is a random number

$\endgroup$
  • $\begingroup$ Please show a complete but minimal example that illustrates the problem. $\endgroup$ – Szabolcs Dec 3 '19 at 18:32
  • $\begingroup$ $ can mean dollars, as in the output from evaluating Quantity[10, "Dollars"]. $\endgroup$ – user6014 Dec 3 '19 at 18:40
  • 2
    $\begingroup$ From the documentation for Module: "Module creates a symbol with name xxx\$nnn to represent a local variable with name xxx. The number nnn is the current value of \$ModuleNumber. " $\endgroup$ – Bob Hanlon Dec 3 '19 at 23:16
13
$\begingroup$

This usually means you've exported a local symbol from the context in which it was localized. Consider:

Module[{x}, x]
(* x$24939 *)

Your results may vary. The Module localizes x to avoid conflicting with any previous definition. x$24939 is just another symbol similar to x, but with $24939 added to its name to insure that there's no confusion with any other x.

To yield the symbol without modification, remove it from the list of symbols localized by Module.

$\endgroup$
  • $\begingroup$ So, what may I do to resolve this conflict? $\endgroup$ – pinpose23 Dec 3 '19 at 18:55
  • 3
    $\begingroup$ @pinpose23 For me, I usually have to fix the problem with my code. $\endgroup$ – Michael E2 Dec 3 '19 at 19:22
5
$\begingroup$

Your code is working as intended, I would think:

Q[q_, x1_, y1_, l1_, l2_, l3_, l4_] :=
 Module[{x2, y2, x3, y3, x4, y4, theta1, theta2},
   x2 = x1 + l1 Cos[q];
   y2 = y1 + l1 Sin[q];
   (*others*)
   {x2, y2, y3, x3, theta1, theta2}
 ]

Q[q, 0, 0, 3, 5, 2, 4]

This returns:

{3 Cos[q], 3 Sin[q], y3$62555, x3$62555, theta1$62555, theta2$62555}

The calculated values of x2 and y2 are returned but, since you do not have definitions for y3, x3, theta1, theta2 in your Module, they are returned unevaluated in their localized form, as mentioned above.

To avoid this, you need to provide definitions for those values as well.

Notice also that your original code was missing a _ after x1 in the argument list of Q.

$\endgroup$

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