Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


x[t_] := {Subscript[x, 1][t], Subscript[x, 2][t]}

following replace works fine

x[t] /. x[t] -> 0

but following one is a problem

x[t] - 1 /. x[t] -> 0
{-1 + Subscript[x, 1][t], -1 + Subscript[x, 2][t]}

because I expect there '-1'.

share|improve this question
up vote 3 down vote accepted

First and foremost, x is a vector, so perhaps you meant x[t]-{1,1}. But your problem is another one, and it is linked to the 'overarching evaluation' of Mathematica. (Maybe one day, if I find the time, I'll add an entry to the Pitfalls in Mathematica post, since this is one of the most common pitfalls new users fall in).

When you ask MMA to evaluate

x[t] - 1 /. x[t] -> 0

A statement equivalent to

ReplaceAll[x[t] - 1, x[t] -> 0]

Mathematica evaluates the arguments of ReplaceAll before calling ReplaceAll itself. So, what ReplaceAll sees is (I won't use subscripts for brevity, hence for me x[t_]:={x1[t],x2[t]}) EDIT: corrected my blunder

 ReplaceAll[{x1[t],x2[t]} - 1, {x1[t],x2[t]} -> 0]

and there is no valid rule to apply there. You might want to specify the vector's components as in

 ReplaceAll[x[t] - 1, {x1[t] -> 0,x2[t]->0}]

Or, in short (using the improper mixture of vectors and scalars you are using)

 ReplaceAll[x[t] - 1, Thread[x[t] -> 0]]

But I would use vectors instead of 1 and 0, either by specifying their components {1,1} and {0,0} or by defining a zeroVec and a unityVec with those components.

If you want to specify vectors as symbols only, either you use some sort of Holdind and Releaseing to avoid the overarching evaluator, or you revise the way you define your vectors (for example by leaving vectors undefined and using replacement rules to specify their components at the end of your 'vector symbolic' calculations).

share|improve this answer
Thank you for help. Of course it is better to use {0, 0} and {1, 1} in this example. – V_V Nov 20 '13 at 23:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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