Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Setting up Looping Constructs' topicStudent Support Forum > General > "Setting up Looping Constructs"

Next Comment >Help | Reply To Topic
Author Comment/Response
Michael Senter
07/15/13 00:51am

I'm trying to figure out how to create looping constructs properly in Mathematica. My current test problem involves a strong of information, represented by a list of 0's. I wrote a function that goes over each element in a list and creates a weighted random variable value - the two values are compared, if they differ the original 0 is replaced by a 1, otherwise it's left alone. Counting the 1's later tells me how many bits of information were lost.

I want to be able to write a loop/recurrence function that runs my function transcription[] multiple times over a given starting list, thereby accumulating more and more errors.

Here's a Do loop I've tried:

y := RandomChoice[{0.8, 0.2} -> {0, 1}];
transcription[x_] := If[x == y, x, x /. x -> 1];
list = Table[0, {30}];
Print[Do[
list = transcription /@ list, {10}]
]

And a For-loop:

y := RandomChoice[{0.8, 0.2} -> {0, 1}];
transcription[x_] := If[x == y, x, x /. x -> 1];
list = Table[0, {30}];
Print[For[i = 0, i < 10, i++,
list = transcription /@ list]]

Neither of these return any value. Ideas on how do go about this?

Attachment: Looping.nb, URL: ,

Subject (listing for 'Setting up Looping Constructs')
Author Date Posted
Setting up Looping Constructs Michael Senter 07/15/13 00:51am
Re: Setting up Looping Constructs Bill Simpson 07/17/13 8:15pm
Next Comment >Help | Reply To Topic