       Re: Subscripted variables and function definitions

• To: mathgroup at smc.vnet.net
• Subject: [mg65265] Re: Subscripted variables and function definitions
• From: Peter Pein <petsie at dordos.net>
• Date: Thu, 23 Mar 2006 06:58:23 -0500 (EST)
• References: <dvdida\$a26\$1@smc.vnet.net> <dve4na\$ffg\$1@smc.vnet.net> <dvgskl\$9rc\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Geico Caveman schrieb:
...
> Actually, that was a typo in my post. I am using X[]/(X[]+X[]) and
> I get what I described.
>
> Any ideas ?
>

Hi Geico,

you propably want to Evaluate[] the definition:

In:= X = {x1, x2, x3, x4};
In:= f[x1_, x2_, x3_, x4_] := X[]/(X[] + X[])
In:= f[1, 1, 1, 1]
Out= x1/(x3 + x4)

In:= g[x1_, x2_, x3_, x4_] := Evaluate[X[]/(X[] + X[])]
In:= g[1, 1, 1, 1]
Out= 1/2

In:= h[x1_, x2_, x3_, x4_] = X[]/(X[] + X[])
Out= x1/(x3 + x4)
In:= h[1, 1, 1, 1]
Out= 1/2

If you call f[1,1,1,1], Mathematica looks for occurances of x1..x4 in your definition of f and doesn't find any, because f is defined with SetDelayed (":=").
_After_ this it takes X[]/(X[] + X[]) and evaluates this expression.

g is defined using SetDelayed too, but now Mathematica finds the patterns x1..x4 in the expression, replaces them by actual values and evaluates the result.

h has been defined using Set. Set Evaluates its second argument _before_ assigning the result to a name.

To see how Mathematica stores these three functions, enter ?f or ?g or ?h.

A look at "The Mathematica Book" 2.5.8 might help too.

Hope this helps,
Peter

```

• Prev by Date: Re: A question concerning Show and PlotLegend
• Next by Date: Re: How to sample a 2-dim. r.v. with known density function?
• Previous by thread: Re: Subscripted variables and function definitions
• Next by thread: Is this a BUG of D[f, var1, ..., NonConstants -> {u1, ...}] ?