Fixing fzero in standard normal distribution

I am trying to solve a variable n used in this equation for normal distribution
Z = (X - mean) / std
mean = 500*n
std = sqrt(500*n*(1-n))
X = 440
Z = -2.33
This is the code i am trying to use to solve it
N = @(n) (((440 - 500*n)/(sqrt(500*n*(1-n))))+2.33)
N = function_handle with value:
@(n)(((440-500*n)/(sqrt(500*n*(1-n))))+2.33)
fzero(N,0)
Error using fzero
Initial function value must be finite and real.
How do you suggest I change it so I get a real value from n?

 Accepted Answer

Change the initial parameter estimate to something other than 0. The fzero function is a root-finding algorithm, so it looks for zero-crossings.
Perhaps something like this —
N = @(n) (((440 - 500*n)/(sqrt(500*n*(1-n))))+2.33)
N = function_handle with value:
@(n)(((440-500*n)/(sqrt(500*n*(1-n))))+2.33)
nv = fzero(N,rand)
nv = 0.9098
.

2 Comments

Thank you! Why does rand work? If I remember correctly rand is just random numbers?
As always, my pleasure!
It is just that. However it is a random number between 0 and 1, so limited in its amplitude.

Sign in to comment.

More Answers (1)

Note that your problem has a closed-form solution, i.e. fzero is not necessary:
X = 440; Z = -2.33;
syms n; assume(X-500*n<=0)
n=double( solve( (X - 500*n)^2 == 500*n*(1-n)*Z^2 ) )
n = 0.9098

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!