Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14510 > unrolled thread

How do you control evaluation when using apply?

Started byBrentt <brenttnewman@gmail.com>
First post2013-05-16 07:28 +0000
Last post2013-05-17 08:34 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  How do you control evaluation when using apply? Brentt <brenttnewman@gmail.com> - 2013-05-16 07:28 +0000
    Re: How do you control evaluation when using apply? Roland Franzius <roland.franzius@uos.de> - 2013-05-17 08:34 +0000

#14510 — How do you control evaluation when using apply?

FromBrentt <brenttnewman@gmail.com>
Date2013-05-16 07:28 +0000
SubjectHow do you control evaluation when using apply?
Message-ID<kn21qq$1hl$1@smc.vnet.net>
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.

[toc] | [next] | [standalone]


#14514

FromRoland Franzius <roland.franzius@uos.de>
Date2013-05-17 08:34 +0000
Message-ID<kn4q28$2am$1@smc.vnet.net>
In reply to#14510
Am 16.05.2013 09:28, schrieb Brentt:
> 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.
>
>


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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web