The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: List Replace Problems
Replies: 8   Last Post: Aug 30, 2005 4:44 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 24
Registered: 12/13/04
List Replace Problems
Posted: Aug 23, 2005 5:01 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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}];

{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};

({1, 2, 3, 4, 5}) in assignment of part is not a symbol. ! More ...

{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?



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.