normcdf(-1.8611) ans = 0.0314 normcdf(-1.8614) ans = 0.0313 normcdf(5) ans = 1.0000 normcdf(-5) ans = 2.8665e-07 for i = 1:50 x=randn(100000,1); pf(i) = sum(x>5)/100000; end hist(pf) max(pf) ans = 0 for i = 1:50 x=randn(100000,1); pf(i) = sum(x>5)/100000; end for i = 1:50 x=randn(100000,1); pf(i) = sum(x>3)/100000; end hist(pf) normcdf(-3) ans = 0.0013 var(pf) ans = 1.9720e-08 for i = 1:50 x=randn(10000000,1); pf(i) = sum(x>3)/10000000; end whos Name Size Bytes Class Attributes ans 1x1 8 double i 1x1 8 double pf 1x50 400 double x 10000000x1 80000000 double figure hist(pf) var(pf) ans = 1.2226e-08 x = -4:.1:10; fx = normpdf(x); help normpdf NORMPDF Normal probability density function (pdf). Y = NORMPDF(X,MU,SIGMA) returns the pdf of the normal distribution with mean MU and standard deviation SIGMA, evaluated at the values in X. The size of Y is the common size of the input arguments. A scalar input functions as a constant matrix of the same size as the other inputs. Default values for MU and SIGMA are 0 and 1 respectively. See also normcdf, normfit, norminv, normlike, normrnd, normstat. Reference page in Help browser doc normpdf hy = normpdf(x,3,1); plot(x,fx,'b',x,hy,'r'); line([3 3],[0.4]); line([3 3],[0 .4]); xrbf = randn(10000,1); grbf = 3-xrbf; failbf = grbf<0; pfbf = sum(failbf)/length(failbf) pfbf = 1.0000e-03 normcdf(-3) ans = 0.0013 xrbf = randn(1000,1); grbf = 3-xrbf; failbf = grbf<0; pfbf = sum(failbf)/length(failbf) pfbf = 0.0030 plot(xrbf(1:25),0,'o'); plot(x,fx,'b',x,hy,'r'); hold Current plot held plot(xrbf(1:25),0,'o'); xris = rand(1000,1)+3; xris = randn(1000,1)+3; gris = 3-xris; failis = gris<0; pfis = sum(failis)/length(failis) pfis = 0.4830 pfis = sum(failis.* (normpdf(xris)./normpdf(xris,3,1)))/length(failis); pfis pfis = 0.0014 xris = rand(10,1)+3; xris = randn(10,1)+3; gris = 3-xris; failis = gris<0;pfis = sum(failis.* (normpdf(xris)./normpdf(xris,3,1)))/length(failis); pfis pfis = 0.0041 plot(xris(1:25),0,'x'); {??? Index exceeds matrix dimensions. } plot(xris(1:10),0,'x'); axis([-4 10 -/1 /4]) ??? axis([-4 10 -/1 /4]) | {Error: Unexpected MATLAB operator. } axis([-4 10 -.1 .4]) figure plot(xris,(normpdf(xris)./normpdf(xris,3,1)),'x'); xlabel('x'); plot(xris,(normpdf(xris)./normpdf(xris,3,1)),'<'); x1 = -4:.1:7; x2 = x1; for i = 1:length(x1) for j = 1:length(x2) fx(i,j) = mvnpdf([x1(i),x2(j)]); end end surf(x1,x2,fx); {??? Error using ==> surf at 78 Data dimensions must agree. } whos Name Size Bytes Class Attributes ans 1x1 8 double failbf 1000x1 1000 logical failis 10x1 10 logical fx 111x141 125208 double grbf 1000x1 8000 double gris 10x1 80 double hy 1x141 1128 double i 1x1 8 double j 1x1 8 double pf 1x50 400 double pfbf 1x1 8 double pfis 1x1 8 double x 1x141 1128 double x1 1x111 888 double x2 1x111 888 double xrbf 1000x1 8000 double xris 10x1 80 double clear fx for i = 1:length(x1) for j = 1:length(x2) fx(i,j) = mvnpdf([x1(i),x2(j)]); end end whos Name Size Bytes Class Attributes ans 1x1 8 double failbf 1000x1 1000 logical failis 10x1 10 logical fx 111x111 98568 double grbf 1000x1 8000 double gris 10x1 80 double hy 1x141 1128 double i 1x1 8 double j 1x1 8 double pf 1x50 400 double pfbf 1x1 8 double pfis 1x1 8 double x 1x141 1128 double x1 1x111 888 double x2 1x111 888 double xrbf 1000x1 8000 double xris 10x1 80 double surf(x1,x2,fx); for i = 1:length(x1) for j = 1:length(x2) hy(i,j) = mvnpdf([x1(i),x2(j)],[0.5,0.5],[1,1]); end end holdsurf(x1,x2,hy); {??? Undefined function or method 'holdsurf' for input arguments of type 'double'. } hold,surf(x1,x2,hy); Current plot held {??? Error using ==> surf at 78 Data dimensions must agree. } whos Name Size Bytes Class Attributes ans 1x1 8 double failbf 1000x1 1000 logical failis 10x1 10 logical fx 111x111 98568 double grbf 1000x1 8000 double gris 10x1 80 double hy 111x141 125208 double i 1x1 8 double j 1x1 8 double pf 1x50 400 double pfbf 1x1 8 double pfis 1x1 8 double x 1x141 1128 double x1 1x111 888 double x2 1x111 888 double xrbf 1000x1 8000 double xris 10x1 80 double clear hy for i = 1:length(x1) for j = 1:length(x2) hy(i,j) = mvnpdf([x1(i),x2(j)],[0.5,0.5],[1,1]); end end hold on;surf(x1,x2,fx); hold on;surf(x1,x2,hy); diary off