Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: How do you control evaluation when using apply?
Replies: 1   Last Post: May 17, 2013 4:33 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Christoph Lhotka

Posts: 41
Registered: 3/2/10
Re: How do you control evaluation when using apply?
Posted: May 17, 2013 4:33 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hello,

both of your versions work fine in M9.

Here is even a shorter one:

In[]:= jacFun[func_, vars_] :=
Module[{f}, f = Function @@ {{x, y}, D[func, {vars}]};
f @@ # &]

In[]:=jacFun[{Sin[x y], Cos[x + y]}, {x, y}][{10, 2}]


Out[]:={{2 Cos[20], 10 Cos[20]}, {-Sin[12], -Sin[12]}}


BR,

Christoph


On 05/16/2013 09:28 AM, Brentt wrote:
> Why does this work
>
> In[0]: = jacobianFunction[func_, vars_List] := Module[{f},
> f = Function[Evaluate[vars], Evaluate[D[func, {vars}]]];
> f
> ];
> jacobianFunction[{Sin[x y], Cos[x + y]}, {x, y}] @@ {10, 2}
>
> out[0]:= {{2 Cos[20], 10 Cos[20]}, {-Sin[12], -Sin[12]}}
>
> But this does not (the goal is to make the function take a point as an
> argument)
>
>
> In[0]: = jacobianFunction[func_, vars_List] := Module[{f},
> f = Evaluate[Function[Evaluate[vars], Evaluate[D[func, {vars}]]]];
> f@@ # &
> ];
> jacobianFunction[{Sin[x y], Cos[x + y]}, {x, y}][{10, 2}]
>
>
>
> I can't get f@@ # & to evaluate properly (I've tried wrapping it in
> ReleaseHold and evaluate statements, nothing seems to get it to evaluate.
>
> I know I can just rewrite the function to take the point but I'm just
> curious why it won't work.
>
>






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.