Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*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 2002

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

Search the Archive

RE: passing functions as parameters

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34019] RE: [mg33988] passing functions as parameters
  • From: "DrBob" <majort at cox-internet.com>
  • Date: Fri, 26 Apr 2002 03:28:03 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

How's this?

f[x_]:=x^3-x+1
g[x_,y_,s_]:=Which[
    Or[x==y,s[x]==s[y]],"Unknown",
    Xor[s[x]>s[y],x>y],"Decreasing",
    True,"Increasing"
]
g[2,3,f]
g[2,3,-#&]
g[2,2,f]
g[2,-2,#^2&]

"Increasing"
"Decreasing"
"Unknown"
"Unknown"

Bobby Treat


-----Original Message-----
From: GoranG [mailto:icmc2MAKNUTIOVO at pop.tel.hr] 
To: mathgroup at smc.vnet.net
Subject: [mg34019] [mg33988] passing functions as parameters

How would one pass one function to another?

I need to be able to define functions in the following fashion:

f[x_]:=x^3-x+1

g[x_,y_,somefunction?]:=If[somefunction[x]>somefunction[y],"Done","Waiti
ng")

to be able to later on evaluate

g[2.,3., f?]

I have tried couple of paths with no success and would really like to
avoid using global function in function g.

All the best...






  • Prev by Date: Test of a pure function
  • Next by Date: RE: passing functions as parameters
  • Previous by thread: Re: passing functions as parameters
  • Next by thread: RE: passing functions as parameters