Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6119

Re: Coin Toss Sim

From David Bailey <dave@removedbailey.co.uk>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Coin Toss Sim
Date 2011-11-02 11:27 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j8r9e4$3j1$1@smc.vnet.net> (permalink)
References <j89v28$8e$1@smc.vnet.net>

Show all headers | View raw


On 26/10/2011 22:45, pooleman133 wrote:
> I am new to mathematica and am trying to make a coin flipping simulation however mo code isn't working. When I tell it to count the number of head it gives me a bad count. The code I am using is listed below any help would be greatly appreciated.
>
> y[n_] := Block[{g, s},
>
>
>    g := RandomChoice[{"head", "tail"}, n];
>    s := Count[g, "head"];
>    {g, s}
>    ]
>

 From time to time, people post with questions like yours. The basic 
problem is that they really need to learn a bit of Mathematica before 
setting out to solve your own problems - guessing what to do doesn't work!

Rather than give you a piece of working code, I want to show you how to 
learn how to solve a lot of your own problems.

1)    Look up the functions If, While, Do in the help system. Try to 
copy/paste some of the examples into a notebook. Run them and modify 
them to explore what is going on.

2)    Get used to trying the bits of your program on their own. E.g. 
test out the RandomChoice call on its own.

3)    Notice how you can add calls to Print inside code to explore what 
it is doing. For example, in your code you might want to insert the line:

Print[g];

When you write a piece of code that is any way tricky, it is usually 
best to add the Print calls to see what is going on, then take them out 
later.

4)    Until you really know what you are doing, always use Set (=) to 
assign to variables, and SetDelayed (:=) to define functions.

David Bailey
http://www.dbaileyconsultancy.co.uk

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Coin Toss Sim pooleman133 <poolebc221@gmail.com> - 2011-10-26 21:45 +0000
  Re: Coin Toss Sim Rui <rui.rojo@gmail.com> - 2011-10-27 10:40 +0000
  Re: Coin Toss Sim "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-10-28 09:33 +0000
    Re: Coin Toss Sim "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-10-29 11:21 +0000
  Re: Coin Toss Sim Dan Dubin <ddubin@ucsd.edu> - 2011-10-29 11:15 +0000
  Re: Coin Toss Sim DrMajorBob <btreat1@austin.rr.com> - 2011-10-29 11:20 +0000
  Re: Coin Toss Sim "Chris Degnen" <degnen@cwgsy.net> - 2011-11-01 05:10 +0000
  Re: Coin Toss Sim David Bailey <dave@removedbailey.co.uk> - 2011-11-02 11:27 +0000

csiph-web