Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

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

I have an array of functions in terms of a[0] through a[n] and I wish to replace the a[]'s with previously calculated values p[0] through p[n], as in below:

p = Table[Chop[NIntegrate[f[t]*wt[t]*Tn[t], {t, 0, 1}]/(Pi/2)], {n, 0, k}];
p[[1]] = p[[1]]/2;

s = Table[Coefficient[pmult[j], tstar[i], 1], {j, 0, k}, {i, 1, k}]


What is the best way of doing this? I have tried the Replace[], ReplaceAll[], and /. commands but none seem to be giving me what I want. I just want a[0] replaced with the number contained in p[0], a[1] replaced with p[1], etc.

Thanks in advance!

share|improve this question
perhaps just q3 = s / a :> p – Dr. belisarius Jan 24 '14 at 17:49
@Belisarius I believe you have missed the point :-))) – Peltio Jan 24 '14 at 18:19
@Peltio The point was left as an exercise to the reader .) – Dr. belisarius Jan 24 '14 at 18:25
up vote 1 down vote accepted

To use /., you have to supply a replacement Rule rather than just a value. On the left hand side of the Rule (indicated by "->") you supply a pattern; on the right hand side you supply an expression to substitute for the pattern.

In your target vector s, each element depends on symbols like a[i]. For example,

s = {f[1][a[1]], f[2][a[1],a[2]]}

You want to replace every a[i] with the corresponding element of the list p, p[[i]]. You need a list of replacement Rules to get them all at once:

s /. Table[a[i] -> p[[i]], {i, 2}]


s /. Thread[{a[1], a[2]} -> p]
share|improve this answer
That works perfectly! Thanks! – gKirkland Jan 26 '14 at 20:48

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.