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 would like to know how I to define a function with a nested set of parameters (or whatever you would like to call it). For example, how would I get the following function A,

M = m1 + m2;
\[Eta] = m1*m2/(m1 + m2)^2
A[t_]:= M (\[Eta] / M * t)^(1/4);

Such that if I just evaluated A[5.0] for example it would return,

1.49535 M Power[\[Eta]/M, (4)^-1]

(i.e. a function of M and \[Eta]) or something similar, but not A as a function of m1, m2,

1.49535 Power[(m1 m2)/(m1+m2)^2, (4)^-1] (m1+m2)

But, at the same time, maintain a form that I could replace either m1 and m2 or M and \[Eta], such that both

A[5.0] /. m1 -> 1 /. m2 -> 1
A[5.0] /. M -> 2 /. \[Eta] -> 1/4

would return 1.77828.

share|improve this question
Don't use capital letters for the starting char of your vars/functions. You'll collide with Mma internal symbols – Dr. belisarius Sep 14 '12 at 6:51

You could define (heeding @belisarius comment) :

bigM[m1_, m2_] = m1 + m2;
\[Eta][m1_, m2_] = m1*m2/(m1 + m2)^2
bigA[m_, eta_, t_] := m (eta/m*t)^(1/4);

Then :

bigA[m, eta, 5.0]
(* 1.49535 (eta/m)^(1/4) m *)

bigA[bigM[1, 1], \[Eta][1, 1], 5.0]
(* 1.77828 *)
share|improve this answer
Thanks @b.gatessucks, I guess that would work. But in the latter example, I would have to input the m1, m2 data twice. – ShaunH Sep 14 '12 at 6:50

As belisarius comments it is best to avoid using Symbol names that are or start with capital letters to avoid collisions with existing or future system functions. Nevertheless I will preserve your usage for clarity.

Taking the question at face value you might use something like this:

def[_, value_?NumericQ] := value
MakeBoxes[def[name_, value_], _] := name

M = def["M", m1 + m2];
\[Eta] = def["\[Eta]", m1*m2/(m1 + m2)^2];
A[t_] := M (\[Eta]/M*t)^(1/4);

1.49535 M (\[Eta]/M)^(1/4)
A[5.0] /. m1 -> 1 /. m2 -> 1
A[5.0] /. M -> 2 /. \[Eta] -> 1/4


If this does not work in practice you will need to provide some additional context for your question.

share|improve this answer

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.