I would like to do a replace in an expression...
a = t;
b = 1;
a/.t->Range[1,5] (*returns: {1,2,3,4,5} *)
b/.t->Range[1,5] (*returns: 1 *)
but I would like to force the second output to return
{1, 1, 1, 1, 1}
Is there a way I can do this? My expression for "b" will be changing so I thought it would be nice if I could just force it to do this (like map but for expressions).
Thanks!
EDIT: Edit to clarify what I am trying to do.
I have an expression of "t" that changes as I make calculations. For example, let the expression be
express = t^2; (* OR t, OR 1, OR 3*t+t^2 *)
I then would like to evaluate this expression at several values of t so I do the following.
tSet = Range[1,5]
express/.t->tSet
where I will get a list if the expression contains "t". If the expression is constant
express = 1;
express/.t->tSet (* will output just 1, I would like it to be list of ones of length 5 to match tSet *)
I just get the scalar value, 1.
I don't want to create a function that does this unless I absolutely have to.
Hope that makes more sense...
t
has length 5? You asked forsame length as input
.... $\endgroup$Range[1,5]
in your example is output, not input. We need a more complete example of what you are trying to accomplish. $\endgroup$express = t^2;t=Range@5;Print@expres;
$\endgroup$