Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do you control evaluation when using apply?

16 views
Skip to first unread message

Brentt

unread,
May 16, 2013, 3:28:26 AM5/16/13
to

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.


Roland Franzius

unread,
May 17, 2013, 4:34:16 AM5/17/13
to
Do your evaluation during function body contruction and replace the
Function-head after evaluation

jacobianFunction[func_, vars_List] :=
Module[ {function},
( function[ {vars}, D[func, {vars} ] /.function->Function )]


or apply the Function head to a List construct

jacobianFunction[func_, vars_List] :=
Function@@ { {vars}, D[func, {vars} ] }

More easy define a function generator once for all

MakeFunction = (Set@@{#1,Function@@{##2}}&);

MakeFunction[Subscript[f,1],{x,y},D[f[x,y],x]];

Subscript[f,1]

Function[{x, y}, Derivative[1, 0][f][x, y]]

--

Roland Franzius

0 new messages