i dont get why it says Unrecognized function or variable 'Nbin when i run it
2 次查看(过去 30 天)
显示 更早的评论
clear
clc
clf
sum1=0;
N = 10000;
xx=0:0.01:19;
y1=(xx/2.89).*exp(-xx.^2/5.78);
plot(xx,y1,'b','linewidth',3)
hold on
y=rand(1,N); %y=0:0.01:19;
x=1.7*sqrt(-2*log(y));
sum1=sum1+x;
plot(x,y,'r','linewidth',3)
hold on %den petuxenoume siglisi ton 2 diagramaton
mesi_timi_theoritiki=sqrt((pi*2.89)/2);
mesi_timi_peiramatiki=sum1/N;% oi peiramatiki mesi timi einai migadikis morfhs
x=katanomi1(N);
[count,center]=hist(x,Nbin);
Delta=center(2)-center(1);
pithanotita=count/N;
piknotita=pithanotita/Delta;
hold on
plot(center,piknotita,'ro','linewidth',3)
hold off
set(gca,'frontsize',16)
xlabel('Τιμές της τυχαίας μεταβλητής')
ylabel('Πυκνότητα πιθανότητας')
title('Συνάρτηση πυκνότητας πιθανότητας (pdf)')
回答(1 个)
Mike Croucher
2022-1-26
编辑:Mike Croucher
2022-1-26
It's because you have this line
[count,center]=hist(x,Nbin);
Nbin needs to be defined as the number of bins you want in the histogram and you have not defined it.
Try this:
clear
clc
clf
sum1=0;
N = 10000;
Nbin = 10; % Number of bins for histogram
xx=0:0.01:19;
y1=(xx/2.89).*exp(-xx.^2/5.78);
plot(xx,y1,'b','linewidth',3)
hold on
y=rand(1,N); %y=0:0.01:19;
x=1.7*sqrt(-2*log(y));
sum1=sum1+x;
plot(x,y,'r','linewidth',3)
hold on %den petuxenoume siglisi ton 2 diagramaton
mesi_timi_theoritiki=sqrt((pi*2.89)/2);
mesi_timi_peiramatiki=sum1/N;% oi peiramatiki mesi timi einai migadikis morfhs
x=katanomi1(N);
[count,center]=hist(x,Nbin);
Delta=center(2)-center(1);
pithanotita=count/N;
piknotita=pithanotita/Delta;
hold on
plot(center,piknotita,'ro','linewidth',3)
hold off
set(gca,'frontsize',16)
xlabel('Τιμές της τυχαίας μεταβλητής')
ylabel('Πυκνότητα πιθανότητας')
title('Συνάρτηση πυκνότητας πιθανότητας (pdf)')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!