0
votes

I'am traying to solve for p for a binomial distribution function where p is the probability of success.

I have tried many methods but none of them worked, shown bellow one of the methods that I have used:

syms p

y = 1 - binocdf(5,15,p) == 0.999;

X = vpasolve(y, p,[-1 1]);

This is the error that I got after running the code:

Error using symengine Unable to prove 'p < 0 | 1 < p' literally. Use 'isAlways' to test the statement mathematically. Error in sym/subsindex (line 792) X = find(mupadmex('symobj::logical',A.s,9)) - 1;

Error in sym/privsubsasgn (line 1067) L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);

Error in sym/subsasgn (line 904) C = privsubsasgn(L,R,inds{:});

Error in binocdf (line 63) y(k1) = NaN;

Error in myfun (line 6) y=binocdf(5,15,p)==0.999;

1

1 Answers

2
votes

Use function handle instead of syms function as binocdf() doesn't allow p to be syms variable

y = 1 - binocdf(5,15,p) == 0.999; 

could be rewritten as

y = 1 - binocdf(5,15,p) - 0.999 == 0;
  • Using function handle, omitting the right hand side of the equation
y = @(p)1 - binocdf(5,15,p) - 0.999

fzero() finds the root of a function, in another words solves the equation y == 0

Also the third parameter in binocdf(5,15,p), namely p is a probability ranging from 0 to 1

  • change the range from [-1, 1] to [0, 1]
fzero(y, [0 1])

The entire code is as follows

y = @(p)1 - binocdf(5,15,p) - 0.999;
X = fzero(y, [0 1])

Result

X = 0.7432