0
votes

Hi im coding a homework in mathematica about finding the probability of a program failing, make a plot and a table with the results however Im having trouble getting the last value of the table

Clear[bin1]
bin1[n_, p_, k_] := 
 Module[{prob = (1 - p)^n, i}, 
  Do[prob = (((n - i + 1)/i) (p/(1 - p))) prob, {i, k}]; prob]



distribution = 
  Table[bin1[50, #, k], {k, 0, 50}] & /@ Range[0, .9, .1];

thats the probability calculator prob = Max[Take[distribution, {#}]] & /@ Range[1, 10] thats to take the first value of the table (its the porcentage of failiure)

position = # & /@ Range[0, .9, .1](thats just for the third value)

max = Last[
  Last[Position[distribution, Take[prob {#}] & /@ Range[1, 10]]]]

thats the third value and where i have trouble its supossed to be tha maximum value but the prob{#} part doesnt work i have no idea why

The final table should be: TableForm[{position, prob, max}]

1
you appear to missing a comma in the second Take. That said you dont need to use take at all. Max[Take[distribution, {#}]] & /@ Range[1, 10] can be simply written as Max /@ distribution - agentp

1 Answers

0
votes

See the documentation for Module:

Module[{x,y,…},expr]

specifies that occurrences of the symbols x, y, … in expr should be treated as local.

When you say bin1[n_, p_, k_] := Module[{prob = …}], then prob is only defined inside the Module, and has no value outside.

You can see how this works by playing with it:

In[1]:= Module[{foo}, foo]                                                      

Out[1]= foo$185

Module renames variables inside its scope to have unique names not accessible outside.

You’ll probably need another function to compute prob, or set up bin1[] to compute both distribution and probability.