tags:

views:

59

answers:

2

What do I need to do to make Pa[p] an ASN[P] to come out as numeric values. Abreviated code is given below. roots, PA2[p] and ANS2[p] are created using an i index.

MMA CODE: ********

Clear[x, y, p];
x := BinomialDistribution[n1, p];
y := BinomialDistribution[n2, p];

Pa[p_] := CDF[x, c1] + Sum[PDF[x, j]*CDF[y, c2 - j], {j, c1 + 1, c2}];
Print[TableForm[Table[{p, Pa[p]}, {p, .01, .1, .01}],
             TableHeadings -> {None, {"p", "Pa[p]"}}]];
ASN[p_] := n1*1 + n2* CDF[x, c2] - CDF[x, c1];   
Print[TableForm[Table[{p, ASN[p]}, {p, .01, .1, .01}],
             TableHeadings -> {None, {"p", "ASN[p]"}}]];

p = {.01, .02, .03, .04, .05, .06, .07, .08, .09, .1};
Print[TableForm[
Table[ {r2[[i]], p[[i]], Pa[[i]], ASN[[i]], Pa2[[i]],ASN2[[i]] }, 
      {i, 1,10,1}],               
 TableHeadings -> {None, {"roots", "p", "Pa[p]","ASN[p]","PA2[p]","ASN2[p]"} } ]];

MMA OUTPUT: *******

p   Pa[p]
0.01    0.980277
0.02    0.817478
0.03    0.555413
0.04    0.327922
0.05    0.177956
0.06    0.0916007
0.07    0.0453877
0.08    0.0217882
0.09    0.0101644
0.1 0.00461704

p   ASN[p]
0.01    178.866
0.02    176.136
0.03    167.438
0.04    153.427
0.05    137.505
0.06    122.884
0.07    111.274
0.08    102.986
0.09    97.5368
 0.1    94.1847

roots           p             Pa[p]          ASN[p]             PA2[p]          ASN2[p]
1.17508      0.01   Pa$1660[[1]]    ASN$1660[[1]]   0.977398        64.4721
0.472821     0.02   Pa$1660[[2]]    ASN$1660[[2]]   0.840606             84.1587
0.000638883  0.03   Pa$1660[[3]]    ASN$1660[[3]]   0.583404        89.3915

-0.3770350 .04 Pa$1660[[4]] ASN$1660[[4]] 0.340761 79.3716 -0.7039350 .05 Pa$1660[[5]] ASN$1660[[5]] 0.185355 65.0975 -1. 0.06 Pa$1660[[6]] ASN$1660[[6]] 0.1 52.7007 -1.27609 0.07 Pa$1660[[7]] ASN$1660[[7]] 0.0547126 43.2261 -1.5388 0.08 Pa$1660[[8]] ASN$1660[[8]] 0.0304681 36.1651 -1.79248 0.09 Pa$1660[[9]] ASN$1660[[9]] 0.017227 30.8583 -2.04012 0.1 Pa$1660[[10]] ASN$1660[[10]] 0.00985218 26.7938

+1  A: 

You've defined functions Pa[p_] and ASN[p_], but I don't see where you've defined arrays that you can subscript as arrays. A lot of the definitions you're using here are misisng, so it's difficult to provide working code, but you might want to try

Print[TableForm[
  Table[{r2[[i]], p[[i]], Pa[i*0.1], ASN[i*0.1], Pa2[[i]], ASN2[[i]]}, {i,
    1, 10, 1}], 
   TableHeadings -> {None, {"roots", "p", "Pa[p]", "ASN[p]", "PA2[p]", 
     "ASN2[p]"}}]]

or something similar.

Pillsy
+1  A: 

You are trying to evaluate a list position [[]] of a function [], i.e. when you call Pa[[i]] you'll get gibberish. What you want is Pa[p[[i]]].

Timo
Hi, I tried that but get an error.BinomialDistribution::probparm: Parameter {0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.1} is expected to be a probability between 0 and 1. >It does not seem to be able to extract one element of the vector.CDF[BinomialDistribution[90,{0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.1}],2]+ ...Mary
Mary A. Marion
Check the notation, I don't get any errors.
Timo