How do I make a variable $k_{1x}$ where the $x$ is just a label to denote the magnitude along the x-axis and not an actual defined variable x in the code?

Similarly, if I wanted to make $E_x$ or $E_{0x}$ for electric field notations, not only can I not use a variable subscript, the $E$ is replaced by Exp.

  • 1
    $\begingroup$ E is a built-in function. You should not use symbol names that start with capital letter to avoid conflicts with build-in functions. $\endgroup$
    – Edmund
    Sep 24 '16 at 16:42
  • $\begingroup$ Ok even if I use q_x, how do I do that? $\endgroup$ Sep 24 '16 at 16:47
  • $\begingroup$ Use Indexed for subscripted variables. $\endgroup$
    – QuantumDot
    Sep 24 '16 at 18:21

Does this do what you need?

ClearAll[kx, k, x]
Format[kx[n_]] := Subscript[k, n, x]
kx[1] = 5

If for some reason you actually need variables with subscripts, see How to create symbol whose name has subscript?

  • $\begingroup$ Would the x be integrated if I did Integral(k_1x) here? $\endgroup$ Sep 24 '16 at 21:29
  • $\begingroup$ @NishaMariamJohnson I'm confused. In your qeustion, you said you wanted x as a label, not as a variable. Are you now saying you want it to be a (bound) variable in an integrand? $\endgroup$
    – Alan
    Sep 25 '16 at 1:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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