function

• To: mathgroup <mathgroup at yoda.physics.unc.edu>
• Subject: function
• From: HAY at leicester.ac.uk
• Date: Sun, 25 OCT 92 00:38:11 GMT

>  A question about forming functions.  Suppose I create a series, using

>  a=Normal[Series[Sin[x],{x,0,5}]]

>  giving a = x - x^3/3! + x^5/5!.

>  I now want to use a to create a function of x, which, functionally,
>  is

>  f[x_]:=a.

>  This will not work in practice.  Is there a way to do this?  For
>  something short, as in this example

>  -r. kline

The immediate solution is to use immediate assinment ( = ) instead of
delayed assignment ( := ). Thus -

a=Normal[Series[Sin[x],{x,0,5}]];
f[x_] = a;
f[p]
p - p^3/6 + p^5/120

Other possibilities are (noting that Function has the attribute HoldAll)
g = Function[x,Evaluate[Normal[Series[Sin[x],{x,0,5}]]]];
g[p]
p - p^3/6 + p^5/120

h = Function[x,b]/.b->Normal[Series[Sin[x],{x,0,5}]];  (*NOT :>*)
h[p]
p - p^3/6 + p^5/120

k = Evaluate[Normal[Series[Sin[#],{#,0,5}]]]&
#1 - #1^3/6 + #1^5/120 &
k[p]
p - p^3/6 + p^5/120

From
Allan Hayes
hay at leicester.ac.uk

• Prev by Date: function
• Next by Date: vectors with mma