simhwk4 - Vctor Gonzlez Matrcula: 805386 Problema 1...

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

View Full Document Right Arrow Icon
Víctor González Matrícula: 805386 Problema 1 %exercise 4-1 clear all clc n=100; %varía entre los diferentes casos p1=1/3; p2=2/3; u=rand(n,1); for i=1:n if u(i,1)<p2 x(i)=2; else x(i)=1; end end r=hist(x,2); stem(r) disp([ 'La proporcion de valores iguales a 1 es: ' num2str(r(1)/n)]) a) n=100 La proporción de valores iguales a 1 es: 0.32 b) n=1000 La proporción de valores iguales a 1 es: 0.334 c) n=1000 La proporcion de valores iguales a 1 es: 0.3301 Problema 2 %exercise 4-2 clear all clc n=input( 'Introduzca el #N de probabilidades: ' ); p=[]; for i=1:n disp([ 'Introduzca probababilidad(' num2str(i) ')' ]) p(i)=input( 'Valor:' ); end a=input( 'Cantidad de # aleatorios para generar: ' ); u=rand(a,1); j=1;temp=0; for i=1:a while (j<=n) if u(i,1)<(p(j)+temp) x(i)=j; temp=0; j=1; break ; else temp=temp+p(j); j=j+1; end end end r=hist(x,n)./a Introduzca el #N de probabilidades: 3
Background image of page 1

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

View Full DocumentRight Arrow Icon
Introduzca probababilidad(1) Valor:0.5 Introduzca probababilidad(2) Valor:0.3 Introduzca probababilidad(3) Valor:0.2
Background image of page 2
Image of page 3
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 / 6

simhwk4 - Vctor Gonzlez Matrcula: 805386 Problema 1...

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

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