3
$\begingroup$

I have an expression of the form f = a*x +OverBar[x], where OverBar[x] is just a name, it has not much to do with the variable x. I want D[f,x] = a but Mathematica shows D[f,x] = a +OverBar'[x].

Is there a way to let Mathematica know that OverBar[x] is just a name and it's derivative wrt to x is zero? D[] doesn't take Assumptions as an option afaik.

Also it does not matter whether I take something else say OverHat or UnderBar the issues is still the same D[OverHat[x],x] = OverHat'[x] according to Mathematica.

If nothing helps, is there any notation resembling OverBar that does not become a function of its argument? i.e. that it is just a symbol/name.

$\endgroup$
  • $\begingroup$ Take a look at this, you just have OverBar instead of Subscript $\endgroup$ – swish Feb 17 '17 at 14:56
  • $\begingroup$ Related: (91356) $\endgroup$ – Mr.Wizard Feb 17 '17 at 15:16
  • 2
    $\begingroup$ Could use Dt: In[78]:= Dt[a*x + OverBar[x], x, Constants -> {a, OverBar}] Out[78]= a $\endgroup$ – Daniel Lichtblau Feb 17 '17 at 16:30
2
$\begingroup$

If you prefer not to have to make the replacement each time:

OverBar'[x] = 0;

f = a*x + OverBar[x]

D[f, x]
a*x + OverBar[x]

a
$\endgroup$
2
$\begingroup$

Just put OverBar'[p] or whatever variable to zero after differentiation. Nothing fancy but should do the job. Something like

D[f,x]//ReplaceAll[#, OverBar'[x] -> 0] & 

Or make a list and set all the OverBar'[par] in the world to zero, where par is any of your (my) parameters.

$\endgroup$
  • 2
    $\begingroup$ No need to do it after differentiation; you can set OverBar'[x] = 0 at the beginning and it should work too. $\endgroup$ – Mr.Wizard Feb 17 '17 at 12:35
  • $\begingroup$ Yup that's right, in some cases that's better. $\endgroup$ – Your Majesty Feb 17 '17 at 12:36
  • 2
    $\begingroup$ Incidentally D[f,x] /. OverBar'[x] -> 0 $\endgroup$ – Mr.Wizard Feb 17 '17 at 12:40
2
$\begingroup$

I wouldn't use OverBar[x] and x together. For example:

Solve[a x + OverBar[x] == 2, x] //InputForm

DynamicSolve::nsmet: This system cannot be solved with the methods available to Solve.

Solve[a*x + OverBar[x] == 2, x]

However, it is possible to get an object that looks like OverBar[x], but doesn't actually include x. If you entered OverBar[x] explicitly as OverBar[x] in your code, you could instead use:

OverBar[RawBoxes@"x"]

enter image description here

(I replaced the above output with an image of what one would see in a notebook).

The box structure is identical:

ToBoxes[OverBar[x]]
ToBoxes[OverBar[RawBoxes@"x"]]

OverscriptBox["x", "_"]

OverscriptBox["x", "_"]

This construct is completely independent of x, so now Solve and D will work as expected:

Solve[a x + OverBar[RawBoxes@"x"] == 2, x]

enter image description here

(Again, the above is an image)

D[a x + OverBar[RawBoxes@"x"], x]

a

Now, it might be that you like to use keyboard shortcuts to create the OverBar object, and the above approach won't work for you. In that case you can add a MakeExpression rule as follows:

MakeExpression[OverscriptBox["x", "_"], StandardForm] := HoldComplete[OverBar[RawBoxes@"x"]]

Now, the object created by the key strokes:

x, control + 7, _

will be interpreted as the OverBar[RawBoxes@"x"] expression I give above.

$\endgroup$

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.