Extracting the body of a function

I have a very simple issue with Mathematica, but I can't seem to find an answer for it.

I solved an equation with DSolve, and I got a result as an array of the following type:

Solution = { A11 -> Function[ {t} , expression1] , A22 ->Function[ {t}, expression 2] , etc }

Now I want to define a matrix with elements {{A11, A12},{A21, A22}} and to give these elements the values for expression1, expression 2, etc, essentially to put those functions in a matrix:

{{ expression 1, expression 2},{ expression 3, expression 4}}

What I tried so far is to use

R11 = {A11} /. Solution[]

, but it gives R11 the value Function [ {t} , expression 1] and not expression 1.

How can I solve this issue?

• g = Function[{t}, expression1 t]; Module[{t}, g[]] Nov 14 '14 at 12:58
• This just gives Function[{t},expression 1]. I want to extract expression 1 out of there. Nov 14 '14 at 13:02
• No, it returns expression1 t, at least in Mathematica v9. Nov 14 '14 at 13:08

There are two syntaxes for DSolve:

In:= DSolve[x''[t] + x[t] == 0, x, t]
Out= {{x -> Function[{t}, C Cos[t] + C Sin[t]]}}

In:= DSolve[x''[t] + x[t] == 0, x[t], t]
Out= {{x[t] -> C Cos[t] + C Sin[t]}}

Notice that one returns the solution for x, the other for x[t]. Both are meant to be substituted into x[t], and will give the same result after the substitution:

In:= x[t] /. %5
Out= {C Cos[t] + C Sin[t]}

In:= x[t] /. %6
Out= {C Cos[t] + C Sin[t]}

So the key is to use {{A11[t], A12[t]},{A21[t], A22[t]}} instead of {{A11, A12},{A21, A22}}.

Generally, the "extract the expression in a Function" just means applying the function: Function[x, x^2][t] gives t^2.

If you use MMA 10 try DSolveValue instead of DSolve. In this case may help this:

(*extracting expressions from Function*)
t = Solution /. func_Function :> func[];
(*extracting expressions from Rule*)
t /. rule_Rule -> rule[]
• WORKS: The way to solve the problem is the following element = Res /. func_Function :> func[] and then combine it with RhoSol = {{\[Rho]11 /. element[], \[Rho]12 /. element[]}, {\[Rho]21 /. element[], \[Rho]22 /. element[]}}; Works great, thanks! Nov 14 '14 at 13:49

Another solution (make a matrix of elements Aij[t] and substitute the functions you have found):

sol = {A11 -> Function[{t}, expression1], A12 -> Function[{t}, expression2],
A21 -> Function[{t}, expression3], A22 -> Function[{t}, expression4]};

Partition[Through[{A11, A12, A21, A22} [t]], 2] /. sol

(* {{expression1, expression2}, {expression3, expression4}} *)

ClearAll[t];
{#[], #[], #[]} &@Function[{t}, expression1 t] //Column

(*
Function
{t}
expression1 t

*)