Fixing fzero in standard normal distribution

5 views (last 30 days)
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

Star Strider
Star Strider on 24 Feb 2023
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
MADISON RAGONE
MADISON RAGONE on 24 Feb 2023
Thank you! Why does rand work? If I remember correctly rand is just random numbers?
Star Strider
Star Strider on 24 Feb 2023
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)

Matt J
Matt J on 24 Feb 2023
Edited: Matt J on 24 Feb 2023
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

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!