相关代码 |
|
clear;clc; N=10000; a = -3.; b=3.; W = 0.01; X = randn(1,N); Y = X.^2; N = length(Y) %prog=(a:W:b); prog2=(a:W:b); [nr nc] = size(prog2); for i1=1:nc ref(i1)=(1./(sqrt(2*pi*prog2(i1))))*exp((-prog2(i1))/(2)); K=find(Y > prog2(i1)); kc = length(K); F(i1)=kc; end for i1=1:nc-1 p(i1)=(F(i1)-F(i1 + 1))/(N*W); end prog1=prog2(1:nc-1); plot(prog1,p,'r*',prog2,ref,'g')