A have a list of coefficients, and each one of them depends on xp, which I haven't defined so far. For example, A[[1]] reads:
A[[1]]=-((I (a^2 m^2 + 2 (-1 + xp)^2 λ +
a m (I - I xp + 2 (-2 + Q^2) ω) + ω (Q^4 ω +
2 xp (-I + 2 ω - xp^3 ω + xp (I + ω)) +
Q^2 (I - 2 ω + 2 xp^2 ω -
xp (I + 4 ω)))))/(4 (-1 + xp)^2 (I + a m + Q^2 ω - xp (I + 2 ω))))
Later on, I define xp as a function of a and Q. So I would like to do something like this:
y[a_, Q_] := A[[1]] /. xp -> xp[a, Q]
However, when I compute y[0,0], this is what I get:
-((I (a^2 m^2 + a m (I + 2 (-2 + Q^2) ω - I xp[0, 0]) +
2 λ (-1 + xp[0, 0])^2 + ω (Q^4 ω +
Q^2 (I - 2 ω - (I + 4 ω) xp[0, 0] +
2 ω xp[0, 0]^2) +
2 xp[0, 0] (-I +
2 ω + (I + ω) xp[0, 0] - ω xp[0,
0]^3))))/(4 (-1 + xp[0, 0])^2 (I + a m +
Q^2 ω - (I + 2 ω) xp[0, 0])))
The a's and Q's are not 0, except when they are arguments of the function xp[a,Q].
My question is: how can I define y[a_,Q_] such that the a's and Q's get replaced by whatever values are given to the function?
Set
(=) instead ofSetDelayed
.y[a_, Q_] = A[[1]] /. xp -> xp[a, Q]
. $\endgroup$ – Anjan Kumar Jul 12 '17 at 2:59xp
withxp[0,0]
as you told it. So what is the issue? When later you cally[1,1]
say, it will now replacexp
withxp[1,1]
and so on. $\endgroup$ – Nasser Jul 12 '17 at 3:07y[a_, q_] = A0 /. xp -> xp[a, q]
? This will replacexp
byxp[a,q]
first, and the result, is the body of the function. It is important to know the difference between=
and:=
in function definition. (But I still do not see what difference this will make in your case, as the final result will be the same). $\endgroup$ – Nasser Jul 12 '17 at 3:18