       [no subject]

• To: mathgroup at yoda.physics.unc.edu
• Date: Tue, 27 Oct 92 14:58:38 EST

```thanks to the more than two dozen people who responded to my
inquiry about converting a series to a function.  a few people
asked me to pass on any responses.  I'm attaching a few represetative
ones.

-r. kline

==========================================================================

In:= f = (Normal[Series[Sin[x],{x,0,5}]] /. x->#)&

Out= Normal[Series[Sin[x], {x, 0, 5}]] /. x -> #1 &

In:= f[x]

3    5
x    x
Out= x - -- + ---
6    120

In:= f[r]

3    5
r    r
Out= r - -- + ---
6    120

==========================================================================
The transforming of general expressions into functions is something
that I regularly accomplish with the following inelegant but quick
solution.  Say I have an exression called bob:

In:= bob = Normal[ Series[ Sin[x], {x,0,5} ] ]

3    5
x    x
Out= x - -- + ---
6    120

Now turn that into a function:

In:= fun[z_]:=bob/.{x->z}

It now has all of the properties of ordinary functions of arbitrary arguments:

In:= fun[alpha]

3        5
alpha    alpha
Out= alpha - ------ + ------
6       120

In:= D[fun[alpha],alpha]

2        4
alpha    alpha
Out= 1 - ------ + ------
2        24

==========================================================================

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

Out=
3    5
x    x
x - -- + ---
6    120
In:=
f[x_]:=a

The definition of the function f is not exactly what you want.

In:=
??f
Global`f

f[x_] := a

The reason is that ":=", or in FullForm SetDelayed[],  has the attribute HoldAll
, which means it does not evaluate it's arguments.  In this example it means tha
t "a" does not evaluate to the series with "x" in it.

In:=
Attributes[SetDelayed]

Out=
{HoldAll, Protected}
You can force evaluation of the right hand side by the following definition:

In:=
f1[x_] := Evaluate[ a ]
Note that you now get the desired result.

In:=

??f1
Global`f1

f1[x_] := x - x^3/6 + x^5/120

Wanting to assign a function to c computed result occurs often.

==========================================================================

What you want instead of f[x_]:=a is f[x_]:=Release[a]. That should do it.

==========================================================================

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.

Define   a=Normal[Series[Sin[x],{x,0,5}]] // InputForm

and then F[x_] := Evaluate[a] // N.

==========================================================================

You need to understand the distinction between Set[ ] ("=") and SetDelayed[ ]
(":=").  With SetDelayed[ ] you form a rule with the *unevaluated* right
hand side.  So if you type f[x_] := a you get exactly what you typed in
and since there is no "x" in "a" there is nothing for the pattern matcher
to match.  It doesn't work.  If you type f[x_] = a the "a" first gets
evaluated to x - x^3/3! + x^5/5! and the rule that you get is then
f[x_] = x - x^3/6 + x^5/120.  This rule will then work.

==========================================================================

You need to do an immediate assignment:

f[x_] = a    (* NOT f[x_] := a *)

```

• Prev by Date: automata package
• Next by Date: speech processing
• Previous by thread: automata package
• Next by thread: speech processing