Is there a way to extract an element from a list of functions, before evaluating the numerical value of the function element in Mathematica? - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-23T10:23:45Z https://mathematica.stackexchange.com/feeds/question/175520 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/175520 4 Is there a way to extract an element from a list of functions, before evaluating the numerical value of the function element in Mathematica? khvillegas https://mathematica.stackexchange.com/users/0 2018-06-18T04:45:22Z 2018-06-18T12:37:26Z <p>Consider a list of functions</p> <pre><code>M[x_]:={Cos[x], Sin[x], x} </code></pre> <p>Say I want to evaluate the first element</p> <pre><code>M[] </code></pre> <p>What Mathematica does is evaluate the entire list at <code>x=1</code> then extracts the first element <code>Cos</code>. For large list and complicated functions, this is costly as I don't need the rest of the list's elements(for now). Is there a way where I can make Mathematica extract the first element first, then evaluate it at <code>x=1</code> instead of the other way around?</p> https://mathematica.stackexchange.com/questions/175520/-/175523#175523 4 Answer by kglr for Is there a way to extract an element from a list of functions, before evaluating the numerical value of the function element in Mathematica? kglr https://mathematica.stackexchange.com/users/125 2018-06-18T10:24:06Z 2018-06-18T10:31:27Z <pre><code>ClearAll[m, m2] </code></pre> <p>Turn your already defined function that returns a list</p> <pre><code>m[x_] := {Cos[x], Sin[x], x} </code></pre> <p>to a list of functions:</p> <pre><code>m2 = Function /@ m[#]; </code></pre> <p>Extract any part using <code>Part ([[.]])</code> and use it with the desired input:</p> <pre><code>m2[][z] </code></pre> <blockquote> <p>Sin[z]</p> </blockquote> <pre><code>m2[][whatever] </code></pre> <blockquote> <p>whatever</p> </blockquote>