1
$\begingroup$

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?

$\endgroup$

closed as unclear what you're asking by MarcoB, m_goldberg, LCarvalho, march, Bob Hanlon Jul 16 '17 at 5:35

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Try using Set(=) instead of SetDelayed. y[a_, Q_] = A[[1]] /. xp -> xp[a, Q]. $\endgroup$ – Anjan Kumar Jul 12 '17 at 2:59
  • $\begingroup$ Now the output is simply y[0,0] $\endgroup$ – Thiago Jul 12 '17 at 3:01
  • $\begingroup$ I can't figure what you are asking. Mathematica did exactly what you asked it to do. It replaced xp with xp[0,0] as you told it. So what is the issue? When later you call y[1,1] say, it will now replace xp with xp[1,1] and so on. $\endgroup$ – Nasser Jul 12 '17 at 3:07
  • $\begingroup$ I want to define the function y[a,Q] in such a way that the a's and Q's appearing in the expression are replaced by, say, 1 and 2 respectively, when I call the function y[1,2]. $\endgroup$ – Thiago Jul 12 '17 at 3:10
  • $\begingroup$ Then just do as Anjan suggested. Write y[a_, q_] = A0 /. xp -> xp[a, q] ? This will replace xp by xp[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
2
$\begingroup$

Does this work as you intend?

y[a2_, Q2_] := A[[1]] /. {xp -> xp[a2, Q2],a->a2,Q->Q2}
$\endgroup$

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