# Solution of a function that is in a variable [duplicate]

If I want to get the solution for a simple function, e.g. a^x, I can use:

a = 2;
Function[x, a^x]


However, if I have the function in a variable, I can't get it to work:

a = 2;
func = a^x
Function[x, func]


Similarly, this doesn't work as wished, which is that the last line provides the result if 2 is put into x:

a = 2;
func = a^x;
der = D[func, x]
Function[x, der]


## marked as duplicate by Kuba♦, m_goldberg, dr.blochwave, user9660, Bob HanlonDec 4 '15 at 14:21

• Function is HoldAll so Function[x, #] &[func], let me find a duplicate. – Kuba Dec 4 '15 at 10:10
• duplicates?: 14686, 22033 related: 10067, 40445, 31985 – Kuba Dec 4 '15 at 10:17
• Intersting. But this doesn't work: # & &[func] – Mockup Dungeon Dec 4 '15 at 10:30
• Because it isn't what I've suggested ;) – Kuba Dec 4 '15 at 10:31
• @Kuba Sure! You didn't suggest it, I was just wondering whether this works as well. – Mockup Dungeon Dec 4 '15 at 11:38

Using Evaluate,

a = 2;
func = a^x;
Function[x, func]
Function[x, Evaluate@func]
(* 2^x *)
(* 4 *)


and

a = 2;
func = a^x;
der = D[func, x];
Function[x, der]
Function[x, Evaluate@der]
(* 2^x Log *)
(* 4 Log *)

• Thanks. Interestingly, it seems the following does not work: Evaluate[#] & – Mockup Dungeon Dec 4 '15 at 10:34