Fixing fzero in standard normal distribution

5 Ansichten (letzte 30 Tage)
MADISON RAGONE
MADISON RAGONE am 24 Feb. 2023
Kommentiert: Star Strider am 24 Feb. 2023
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?

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Matt J
Matt J am 24 Feb. 2023
Bearbeitet: Matt J am 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

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by