I define a function with two variables and an argumment which is a function of this two first variables. For example the function Ttrho below (the two variables are T and Rho and pTt is a function of T or Rho or both):
getAllVariables[expr_] :=
Union@Cases[expr,
Except[__Symbol?(Context@# ===
"System`" &), _Symbol], {1, ∞}, Heads -> True];
Ttrho[T_, ρ_, pTt_] :=
With[{var = getAllVariables[pTt]}, Print[var];
If[Length@var > 0,
Apply[pTt, var /. Thread[var -> {T, ρ}]] 5 0.069/ρ,
pTt*5 0.069/ρ]]
I would like that the three results below must have the same value:
Ttrho[1, 0.1, Function[{T, ρ}, T]]
Ttrho[1, 0.1, Function[{ρ, T}, T]]
Ttrho[1, 0.1, Function[T, T]]
But I obtain actually the following results:
During evaluation of In[1]:= {T,ρ}
Out[1]= 3.45
During evaluation of In[2]:= {T,ρ}
Out[2]= 0.345
During evaluation of In[3]:= {T}
During evaluation of In[3]:= Thread::tdlen: Objects of unequal length in {T}->{1,0.1} cannot be combined.
Out[3]= 3.45
Thank you in advance.
Comments
Post a Comment