Re: variable definition help
- To: mathgroup at smc.vnet.net
- Subject: [mg42400] Re: variable definition help
- From: gohtk at rocketmail.com (goh tat kean)
- Date: Fri, 4 Jul 2003 01:33:17 -0400 (EDT)
- References: <be101c$2jl$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Dear Jay, The help file on defining functions gives the following explanation: If you define a function, f[x_]:= x^2 You can f squares its argument, The argument can be a number. Or it can be a more complicated expression. In[2]:= f[a+1] Out[2]:= (1+a)^2 In[3]:= f[4] Out[3]:= 16 In[4]:= f[3x + x^2] Out[4]:= (3x + x^2)^2 In[5]:= Clear[f] However, if you use f[x], f[x]:= x^2 and, give the following arguments to the function, f[a+1], f[4] and f[3x + x^2] You will obtain, f[1+a], f[4] and f[3x + x^2] Good luck! Regards, tat kean "seferiad" <seferiad at pacbell.net> wrote in message news:<be101c$2jl$1 at smc.vnet.net>... > When defining functions, any of the following seem to be commonly used > (assuming the function is of one variable, x): > > f or f[x] or f[x_]. > > Can someone point me to an explanation that defines the pros/cons of using > one approach over the other. In particular, when I should use f[x] vs. > f[x_]. > > Thanks, Jay