MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Not accepting function as parameter


Clear[happy]
happy[f_Function, a_Integer, b_Integer] := 
   Module[{width = (b - a)/1000}, f[width]]; 

Contrary to intuition the Head of Sin is not Function.

Head[Sin]
Symbol

So turn it into a Function

happy[Sin[#] &, 1, 21]
Sin[1/50]

Or write a more general definition for happy.

Clear[happy]
happy[(f_Function) | (f_Symbol), a_Integer, 
    b_Integer] := Module[{width = (b - a)/1000}, 
    f[width]]; 

happy[Sin, 1, 21]
Sin[1/50]

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/ 



From: wooks [mailto:wookiz at hotmail.com]


This is a piece of experimental code. The function happy does not
evaluate whenever I pass f as a parameter as in the example below.

Clear[happy]
happy[ f_Function, a_Integer, b_Integer] := Module[{width = (b -
a)/1000},
       f[width]];

happy[ Sin, 1, 21]

I'd be grateful for help.



  • Prev by Date: Re: Limit of Infinitely Nested Expression (4.0 succeeds, 5.2 fails...)
  • Next by Date: Re: draw vertical cylinder with no surface lines
  • Previous by thread: Re: Not accepting function as parameter
  • Next by thread: Re: Not accepting function as parameter