i dont get why it says Unrecognized function or variable 'Nbin when i run it

4 visualizaciones (últimos 30 días)
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)')

Respuestas (1)

Mike Croucher
Mike Croucher el 26 de En. de 2022
Editada: Mike Croucher el 26 de En. de 2022
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)')

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by