MathGroup Archive 2005

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

Search the Archive

Re: List Replace Problems

  • To: mathgroup at smc.vnet.net
  • Subject: [mg59870] Re: [mg59831] List Replace Problems
  • From: János <janos.lobb at yale.edu>
  • Date: Wed, 24 Aug 2005 06:31:26 -0400 (EDT)
  • References: <200508230851.EAA03004@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Aug 23, 2005, at 4:51 AM, wesh wrote:

>
> I want to perform some element by element operations on a class of
> lists. For a given list The operation in a much simplified form can be
> characterized by
>
> a = {1, 3, 5, 7, 9};
> Do[a[[i]] /= i, {i, 1, 5}];
> a
>
> Out[38]=
> {1, 3/2, 5/3, 7/4, 9/5}
>
> Now, however, if I try to define a function to do this for a general
> list, namely,
>
> dlst[u_List] =
>    Do[u[[i]] /= i,  {i, 1, 5}];
> a = {1, 3, 5, 7, 9};
> dlst[a];
> a
>
> Set::setps:
> ({1, 2, 3, 4, 5}) in assignment of part is not a symbol. ! More ...
>
> Out[39]=
> {1, 3, 5, 7, 9}
>
> I get the above error. It says I'm trying to assign one number to
> another number. Why does Mathematica perform in the first case but
> refuse to in the second.
>
> I tried
>
> b = Do[ReplacePart[a,  a[[i]]/i, i], {i, 1, 5}]
>
> but it doesn't even bother to return an error message.
>
>
> How, can I get the desired function?
>
> Thanks,
>
> Wesh
>

In[2]:=
a = Table[2*i + 1, {i, 0, 10}]
Out[2]=
{1, 3, 5, 7, 9, 11, 13, 15,
   17, 19, 21}

In[5]:=
dlst[lst_List] :=
   Table[lst[[i]]/i,
    {i, 1, Length[lst]}]

In[6]:=
dlst[a]
Out[6]=
{1, 3/2, 5/3, 7/4, 9/5, 11/6,
   13/7, 15/8, 17/9, 19/10,
   21/11}

János


----------------------------------------------
Trying to argue with a politician is like lifting up the head of a  
corpse.
(S. Lem: His Master Voice)


  • Prev by Date: Re: Distribution and Integral
  • Next by Date: Re: Distribution and Integral
  • Previous by thread: Re: List Replace Problems
  • Next by thread: Re: List Replace Problems