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.