simhwk5 - Estudiante: Vctor Gonzlez Matrcula: 805386...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 f(x) Generada f(x) Real Estudiante: Víctor González Matrícula: 805386 Problema 1 r=10500; m=1.582; k=1/(m*(exp(1)-1)); sum=0; for i=1:r sum=0; a=0; while a==0 y=rand(1); u=rand(1); a=u<=(k*exp(y)); sum=sum+1; end x(i)=y; c(i)=sum; end %Grafica de la variable aleatoria generada [N,I]=hist(x,8); N=N*m/max(N); plot(I,N, '-ro' ) hold on disp([ 'Valor de repeticiones, c= ' num2str(mean(c))]) %Grafica de comparacion t=0:0.25:1; f=exp(t)/(exp(1)-1); plot(t,f, '-b' ) legend( 'f(x) Generada' , 'f(x) Real' ) Valor de repeticiones: 1.5775 Problema 2 r=5000;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 2.5 3 3.5 4 4.5 5 5.5 6 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 f(x) Generada - f(x) Real Estudiante: Víctor González Matrícula: 805386 m1=1/2; m2=1/2; for i=1:r s1=0; s2=0; a1=0; a2=0; while a1==0 y1=2+rand(1); u1=rand(1); a1=u1<=(y1-2)/(2*m1); s1=s1+1; end while a2==0 y2=3+3*rand(1); u2=rand(1); a2=u2<=(2-(y2/3))/(2*m2); s2=s2+1; end x1(i)=y1; x2(i)=y2; c1(i)=s1; c2(i)=s2; end %Grafica de la variable aleatoria generada [N,I]=hist(x1,8); [N2,I2]=hist(x2,8); plot(I,N*m1/max(N), '-ro' ,I2,N2*m2/max(N2), '- ro' ) hold on disp([ 'Valor de repeticiones, c1= ' num2str(mean(c1))]) disp([ 'Valor de repeticiones, c2= ' num2str(mean(c2))]) %Grafica de comparacion t1=2:0.1:3; t2=3:0.1:6; f1=(t1-2)/2; f2=(2-(t2/3))/2; Valor de repeticiones, c1= 2.0505 Valor de repeticiones, c2= 1.982
Background image of page 2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 pdf: f(x) cdf: F(x) generado cdf: F(x) original Estudiante: Víctor González Matrícula: 805386 plot(t1,f1, '-b' ,t2,f2, '-b' ) legend( 'f(x) Generada'
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/01/2011 for the course SIMULACION SEM2 taught by Professor Hernandez during the Spring '11 term at ITESM.

Page1 / 13

simhwk5 - Estudiante: Vctor Gonzlez Matrcula: 805386...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online