Re: Partial evaulation of function terms

• To: mathgroup at smc.vnet.net
• Subject: [mg53256] Re: [mg53230] Partial evaulation of function terms
• From: yehuda ben-shimol <benshimo at bgu.ac.il>
• Date: Mon, 3 Jan 2005 04:29:32 -0500 (EST)
• References: <200501020912.EAA27721@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi Erich,
Since Mathematica works with expressions of the form Head[Body] the
I couldn't figure out how to get the desired effect elegantly without
entering t to the list of argument or remove it totally from the list of
argument (both yield the same result).
Try to enter t a an argument
ParFun[amps_, freq_, t_] := Sum[amps[[i]]*Sin[2*Pi*freq*
i*t], {i, Length[amps]}]
Then
ParFun[{1, 1/2}, 220, t] // InputForm
Will yield

Sin[440*Pi*t] + Sin[880*Pi*t]/2

For the second possibility omit t from the list of arguments
ParFun[amps_,freq_]:=Sum[amps[[i]] Sin[2 Pi freq i t],{i,Length[amps]}]
will do the same
but here you must avoid defining or using t prior to this definition

yehuda

Erich Neuwirth wrote:

>I have the following function definition
>
>ParFun[amps_, freq_] := Function[t, Sum[amps[[i]]*Sin[2*Pi*freq*i*t], {
>     i, Length[amps]}]]
>
>Then, the following works:
>
>ParFun[{1,1/2},220][t]//InputForm
>Sin[440*Pi*t] + Sin[880*Pi*t]/2
>
>but
>ParFun[{1,1/2},220]//InputForm
>	yields
>Function[t\$, Sum[{1, 1/2}[[i]]*Sin[2*Pi*220*i*t\$], {i, Length[{1, 1/2}]}]]
>
>Is there a way to force Mathematica to evaluate all
>subterms which already can be evaluated?
>This function will be called in Play very often, so it would make things
>much faster if you could assign the function with all possible
>constants evaluated to a local variable and do the many calls to the
>function for producing numerical values with the "partially
>preevaluated" expression.
>
>
>

```

• Prev by Date: Re: For to Map to Increase Speed
• Next by Date: Re: Thread
• Previous by thread: Partial evaulation of function terms
• Next by thread: Re: Partial evaulation of function terms