Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

RE: Not accepting function as parameter

  • To: mathgroup at smc.vnet.net
  • Subject: [mg71704] RE: [mg71681] Not accepting function as parameter
  • From: "David Park" <djmp at earthlink.net>
  • Date: Mon, 27 Nov 2006 04:04:15 -0500 (EST)

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