MathGroup Archive 2007

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

Search the Archive

Re: A Problem with x[i_]:=

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83001] Re: A Problem with x[i_]:=
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Tue, 6 Nov 2007 03:48:33 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fgmq4o$9tv$1@smc.vnet.net>

John wrote:

> The assignment, x=N[Total[-2Log[((n)(pdpd)/v[I])^v[i]]],10], executes
---------------------------------------------^^^^
Beware: I (uppercase i) is a system defined symbol, which is equal to 
the imaginary unit sqrt(-1). Therefore, as written, v[I] iwill evaluate 
to v[1.0 * \[imaginary]], I bet not exactly what you expect.

> for i=1,2,..,10, and I can make a list of the 10 outcomes by repeating
> the assignment 10 times.
> 
> I thought that the assignment, x[i_]:=N{Total[-2Log[((n)(pdpd)/
> v[i])^v[i]]],10], would make a list of the 10 outcomes, without the
> necessity of manual repetitions, but Mathematica rejected it.
> 
> The error message tells me that my assignment won't execute because
> times is protected.
> 
> There must be some way to do what I want to do, but I can't figure it
> out.
> 
> I am using Mathematica 6.

The first definition conflicts with the second because Mathematica 
evaluates the LHS of an expression first, so the expression x[i_] := ... 
is going to be evaluates to N[Total[-2 Log[((n) (pdpd)/v[I])^v[i]]], 
10][i_] := ..., the symbol x on the LHS is replaced by its current 
value. To avoid that, erase any anterior definition with Clear (see below).

In[1]:= x = N[Total[-2 Log[((n) (pdpd)/v[I])^v[i]]], 10]

Out[1]= -2.000000000 +
  Log[((n pdpd)/v[1.000000000 \[imaginary]])^v[i]]

In[2]:= x[i_] := N[Total[-2 Log[((n) (pdpd)/v[i])^v[i]]], 10]

During evaluation of In[2]:= SetDelayed::write: Tag Plus in \
(-2.000000000+Log[((n pdpd)/v[1.000000000 \[ImaginaryI]])^v[i]])[i_] \
is Protected. >>

Out[2]= $Failed

In[3]:= Clear[x]
x[i_] := N[Total[-2 Log[((n) (pdpd)/v[i])^v[i]]], 10]

In[5]:= x[1]

Out[5]= -2.000000000 + Log[((n pdpd)/v[1.000000000])^v[1.000000000]]

HTH,
-- 
Jean-Marc


  • Prev by Date: Re: Re: Jagged Spine (MultinormalDistribution)
  • Next by Date: Re: Can you get a package back to a notebook easily?
  • Previous by thread: Re: A Problem with x[i_]:=
  • Next by thread: Reproducing a hash code