I am not pasting my input code here since the website modifies my code. Instead I am attaching a screenshot of my notebook.
Issue: I enter two separate commands (asking Mathematica to differentiate in both case). I expected the answers to be '2' and '0' respectively, but it spits out some weird thing in the second case. Please tell me what went wrong?
In short, I expect Mathematica to identify 'x' and 'x_{p}' (where '_' stands for subscript) as two independent variables while performing the differentiation but it looks like it has some trouble in identifying variable name with a subscript component.
Subscript[x,p]
, which merely formats as $x_p$. Therefore, Mathematica uses the chain rule to differentiate, giving the correct result. Never ever EVER use subscript to denote symbols. Usexp
instead. $\endgroup$MakeBoxes[xp, StandardForm] := SubscriptBox["x", "p"]; MakeExpression[SubscriptBox["x", "p"], StandardForm] := MakeExpression["xp", StandardForm]
. Then in all subsequent evaluations in the session,xp
will display as $x_p$, but will be interpreted asxp
behind-the-scenes. Only then, wouldD[
$x_p$,x]
yield zero as expected. (Try also runningFullForm[
$x_p$]
to understand what's going on). $\endgroup$