SlideShare a Scribd company logo
1 of 6
Año de la Diversificación Productiva y del Fortalecimiento de la
Educación
UNIVERSIDAD NACIONAL
DEL CALLAO
FACULTAD DE CIENCIAS
NATURALES Y MATEMÁTICA
FÍSICA TEÓRICA COMPUTACIONAL II
“EL VALOR DE PI USANDO EL MÉTODO MONTE
CARLO EN FORTRAN Y SCILAB 5.5”
MARCO ANTONIO ALPACA CHAMBA
ESCUELA PROFESIONAL DE: FÍSICA
PROGRAM
IMPLICIT NONE
REAL, INTEGER…
11 -06-2015
Encontrar el valor de pi por el Método MONTE CARLO:
USANDO FORTRAN TENEMOS:
PROGRAM MONTE_PI
INTEGER::S,L
REAL :: X,Y,PI,N,R
OPEN(UNIT=12,FILE='DENTRO.TXT',STATUS='UNKNOWN',ACTION='WRITE')
OPEN(UNIT=13,FILE='FUERA.TXT',STATUS='UNKNOWN',ACTION='WRITE')
PRINT*,''
PRINT*,
'====================================================================='
PRINT*,' EL VALOR DE PI USANDO EL METHODMONTE CARLO'
PRINT*,'==================================================================
===='
PRINT*,''
PRINT*, 'INGRESAR EL NUMBER DE HISTORIAS:'
READ(5,*) N
PRINT*,''
PRINT*,('*',I=1,79)
PRINT '(5X,"RESULTADOS COMPUTACIONALES")'
PRINT*,('*',I=1,79)
DO J=1,N
R=1
IF (MOD(J,500)==0) THEN
!DO WHILE (K<N+1)
S=0
D=0
CALL RANDOM_SEED()
END IF
ENDDO
DO L=1,N
CALL RANDOM_NUMBER(X)
CALL RANDOM_NUMBER(Y)
RALEAT=SQRT(X**2+Y**2)
IF(RALEAT<=(R**2)) THEN
S=S+1
WRITE(12,7)X,Y
ELSE
D=D+1
WRITE(13,9)X,Y
END IF
ENDDO
PI=4*S/N
7 FORMAT(2X,2F8.4)
9 FORMAT(2X,2F8.4)
PRINT*,'EL NUMBER APROXIMADO DE PI ES:',PI
PRINT*,''
STOP
END PROGRAM
USANDO SCILAB TENEMOS:
A=read('DENTRO.txt',15654,2);
x=A(:,1);
y=A(:,2);
B=read('FUERA.txt',4238,2);
x1=B(:,1);
y1=B(:,2);
plot(x,y,'ro')
plot(x1,y1,'b*')
xlabel('coordenada aleatoria(X)','fontsize',4)
ylabel('coordenada aleatoria (Y)','fontsize',4)
title('EL VALOR DE PI USANDO MONTE CARLO','fontsize',5);
program rng_estimate_pi
implicit none
integer,parameter:: NUM_DRAWS_TOTAL =1e7
integer::countDrawsInCircle =0,i
real :: randomPosition (2)
integer:: seedArray (16)
call date_and_time(values=seedArray (1:8))
call date_and_time(values=seedArray (9:16))
call random_seed(put=seedArray)
do i=1,NUM_DRAWS_TOTAL
call random_number( randomPosition )
if((randomPosition(1)**2 + randomPosition(2)**2)<1.0) then
countDrawsInCircle = countDrawsInCircle + 1
end if
end do
print*,''
print*,"el valor estimado de pi es:=", &
4.0*(real(countDrawsInCircle )/ real(NUM_DRAWS_TOTAL ))
end program rng_estimate_pi
USANDO MATLAB TENEMOS:
rand('state',123)
n = 5000;
XY=rand(n,2)*2-1;
isin=sum(XY.^2,2)<1;
m=sum(isin);
piestimate=4*m/n;
pi;
figure('color',[1,1,1]);
plot(XY(isin,1),XY(isin,2),'b.');
axis equal;
USANDO SCILAB TENEMOS:
function [xy, isin, piest]=mcpi(n)
xy = rand(n,2);
xy = xy * 2 - 1;
isin = sum(xy .^ 2, 2) < 1;
m = sum(isin);
piest = 4 * m/n;
endfunction
[xy,isin,piest]=mcpi(5000);
plot(xy(isin,1),xy(isin,2),'b.');
mtlb_axis("equal");
disp('pi_estimado');
disp(piest);

More Related Content

More from Marco Antonio

Prefijos del sistema internacional
Prefijos del sistema internacionalPrefijos del sistema internacional
Prefijos del sistema internacionalMarco Antonio
 
monthly exam of algebra
monthly exam of algebramonthly exam of algebra
monthly exam of algebraMarco Antonio
 
Problemas resueltos de Factorización
Problemas resueltos de FactorizaciónProblemas resueltos de Factorización
Problemas resueltos de FactorizaciónMarco Antonio
 
solucionario del examen de álgebra
solucionario del examen de álgebrasolucionario del examen de álgebra
solucionario del examen de álgebraMarco Antonio
 
Examen Bimestral de Aritmética 5° de primaria
Examen Bimestral de Aritmética 5° de primariaExamen Bimestral de Aritmética 5° de primaria
Examen Bimestral de Aritmética 5° de primariaMarco Antonio
 
Examen Bimestral de Aritmética 6° de primaria
Examen Bimestral de Aritmética 6° de primariaExamen Bimestral de Aritmética 6° de primaria
Examen Bimestral de Aritmética 6° de primariaMarco Antonio
 
Brevísima historia de Arquímedes
Brevísima historia de ArquímedesBrevísima historia de Arquímedes
Brevísima historia de ArquímedesMarco Antonio
 
El principio de Le Chatelier
El principio de Le Chatelier El principio de Le Chatelier
El principio de Le Chatelier Marco Antonio
 
COMPARACIÓN DE LOS MÉTODOS ITERATIVOS DE RUNGE KUTTA 2 ORDEN CON RUNGR KUTTA ...
COMPARACIÓN DE LOS MÉTODOS ITERATIVOS DE RUNGE KUTTA 2 ORDEN CON RUNGR KUTTA ...COMPARACIÓN DE LOS MÉTODOS ITERATIVOS DE RUNGE KUTTA 2 ORDEN CON RUNGR KUTTA ...
COMPARACIÓN DE LOS MÉTODOS ITERATIVOS DE RUNGE KUTTA 2 ORDEN CON RUNGR KUTTA ...Marco Antonio
 
MÉTODO DE RUNGE KUTTA DE 4 ORDEN PARA RESOLVER UNA ECUACIÓN DIFERENCIAL DE SE...
MÉTODO DE RUNGE KUTTA DE 4 ORDEN PARA RESOLVER UNA ECUACIÓN DIFERENCIAL DE SE...MÉTODO DE RUNGE KUTTA DE 4 ORDEN PARA RESOLVER UNA ECUACIÓN DIFERENCIAL DE SE...
MÉTODO DE RUNGE KUTTA DE 4 ORDEN PARA RESOLVER UNA ECUACIÓN DIFERENCIAL DE SE...Marco Antonio
 
COMPARACIÓN DE LOS MÉTODOS ITERATIVOS ADAMAS-BALTHOR-MOULT PREDICTOR CORRECTO...
COMPARACIÓN DE LOS MÉTODOS ITERATIVOS ADAMAS-BALTHOR-MOULT PREDICTOR CORRECTO...COMPARACIÓN DE LOS MÉTODOS ITERATIVOS ADAMAS-BALTHOR-MOULT PREDICTOR CORRECTO...
COMPARACIÓN DE LOS MÉTODOS ITERATIVOS ADAMAS-BALTHOR-MOULT PREDICTOR CORRECTO...Marco Antonio
 
MÉTODO ITERATIVO DE GAUSS_SEIDEL USANDO FORTRAN 90, MATLAB Y SCILAB
MÉTODO ITERATIVO DE GAUSS_SEIDEL USANDO FORTRAN 90, MATLAB Y SCILABMÉTODO ITERATIVO DE GAUSS_SEIDEL USANDO FORTRAN 90, MATLAB Y SCILAB
MÉTODO ITERATIVO DE GAUSS_SEIDEL USANDO FORTRAN 90, MATLAB Y SCILABMarco Antonio
 
Sesion multiplexores y demultiplexores
Sesion  multiplexores y demultiplexores Sesion  multiplexores y demultiplexores
Sesion multiplexores y demultiplexores Marco Antonio
 
Sesion contadores y registros
Sesion  contadores y registrosSesion  contadores y registros
Sesion contadores y registrosMarco Antonio
 
Regla de dispersión numérica
Regla de dispersión numéricaRegla de dispersión numérica
Regla de dispersión numéricaMarco Antonio
 
MÉTODO DE RONGE KUTTA DE CUARTO ORDEN PARA EDO
MÉTODO DE RONGE KUTTA DE CUARTO ORDEN PARA EDOMÉTODO DE RONGE KUTTA DE CUARTO ORDEN PARA EDO
MÉTODO DE RONGE KUTTA DE CUARTO ORDEN PARA EDOMarco Antonio
 
MÉTODO DE EULER PARA EDO Y DE ORDEN SUPERIOR USANDO SCILAB 5.5
MÉTODO DE EULER PARA EDO Y DE ORDEN SUPERIOR USANDO SCILAB 5.5MÉTODO DE EULER PARA EDO Y DE ORDEN SUPERIOR USANDO SCILAB 5.5
MÉTODO DE EULER PARA EDO Y DE ORDEN SUPERIOR USANDO SCILAB 5.5Marco Antonio
 

More from Marco Antonio (20)

Prefijos del sistema internacional
Prefijos del sistema internacionalPrefijos del sistema internacional
Prefijos del sistema internacional
 
monthly exam of algebra
monthly exam of algebramonthly exam of algebra
monthly exam of algebra
 
Factorización
FactorizaciónFactorización
Factorización
 
Problemas resueltos de Factorización
Problemas resueltos de FactorizaciónProblemas resueltos de Factorización
Problemas resueltos de Factorización
 
solucionario del examen de álgebra
solucionario del examen de álgebrasolucionario del examen de álgebra
solucionario del examen de álgebra
 
Examen Bimestral de Aritmética 5° de primaria
Examen Bimestral de Aritmética 5° de primariaExamen Bimestral de Aritmética 5° de primaria
Examen Bimestral de Aritmética 5° de primaria
 
Examen Bimestral de Aritmética 6° de primaria
Examen Bimestral de Aritmética 6° de primariaExamen Bimestral de Aritmética 6° de primaria
Examen Bimestral de Aritmética 6° de primaria
 
Brevísima historia de Arquímedes
Brevísima historia de ArquímedesBrevísima historia de Arquímedes
Brevísima historia de Arquímedes
 
El principio de Le Chatelier
El principio de Le Chatelier El principio de Le Chatelier
El principio de Le Chatelier
 
Arquímedes
ArquímedesArquímedes
Arquímedes
 
COMPARACIÓN DE LOS MÉTODOS ITERATIVOS DE RUNGE KUTTA 2 ORDEN CON RUNGR KUTTA ...
COMPARACIÓN DE LOS MÉTODOS ITERATIVOS DE RUNGE KUTTA 2 ORDEN CON RUNGR KUTTA ...COMPARACIÓN DE LOS MÉTODOS ITERATIVOS DE RUNGE KUTTA 2 ORDEN CON RUNGR KUTTA ...
COMPARACIÓN DE LOS MÉTODOS ITERATIVOS DE RUNGE KUTTA 2 ORDEN CON RUNGR KUTTA ...
 
MÉTODO DE RUNGE KUTTA DE 4 ORDEN PARA RESOLVER UNA ECUACIÓN DIFERENCIAL DE SE...
MÉTODO DE RUNGE KUTTA DE 4 ORDEN PARA RESOLVER UNA ECUACIÓN DIFERENCIAL DE SE...MÉTODO DE RUNGE KUTTA DE 4 ORDEN PARA RESOLVER UNA ECUACIÓN DIFERENCIAL DE SE...
MÉTODO DE RUNGE KUTTA DE 4 ORDEN PARA RESOLVER UNA ECUACIÓN DIFERENCIAL DE SE...
 
COMPARACIÓN DE LOS MÉTODOS ITERATIVOS ADAMAS-BALTHOR-MOULT PREDICTOR CORRECTO...
COMPARACIÓN DE LOS MÉTODOS ITERATIVOS ADAMAS-BALTHOR-MOULT PREDICTOR CORRECTO...COMPARACIÓN DE LOS MÉTODOS ITERATIVOS ADAMAS-BALTHOR-MOULT PREDICTOR CORRECTO...
COMPARACIÓN DE LOS MÉTODOS ITERATIVOS ADAMAS-BALTHOR-MOULT PREDICTOR CORRECTO...
 
MÉTODO ITERATIVO DE GAUSS_SEIDEL USANDO FORTRAN 90, MATLAB Y SCILAB
MÉTODO ITERATIVO DE GAUSS_SEIDEL USANDO FORTRAN 90, MATLAB Y SCILABMÉTODO ITERATIVO DE GAUSS_SEIDEL USANDO FORTRAN 90, MATLAB Y SCILAB
MÉTODO ITERATIVO DE GAUSS_SEIDEL USANDO FORTRAN 90, MATLAB Y SCILAB
 
Sesion multiplexores y demultiplexores
Sesion  multiplexores y demultiplexores Sesion  multiplexores y demultiplexores
Sesion multiplexores y demultiplexores
 
Sesion flips flops
Sesion  flips flopsSesion  flips flops
Sesion flips flops
 
Sesion contadores y registros
Sesion  contadores y registrosSesion  contadores y registros
Sesion contadores y registros
 
Regla de dispersión numérica
Regla de dispersión numéricaRegla de dispersión numérica
Regla de dispersión numérica
 
MÉTODO DE RONGE KUTTA DE CUARTO ORDEN PARA EDO
MÉTODO DE RONGE KUTTA DE CUARTO ORDEN PARA EDOMÉTODO DE RONGE KUTTA DE CUARTO ORDEN PARA EDO
MÉTODO DE RONGE KUTTA DE CUARTO ORDEN PARA EDO
 
MÉTODO DE EULER PARA EDO Y DE ORDEN SUPERIOR USANDO SCILAB 5.5
MÉTODO DE EULER PARA EDO Y DE ORDEN SUPERIOR USANDO SCILAB 5.5MÉTODO DE EULER PARA EDO Y DE ORDEN SUPERIOR USANDO SCILAB 5.5
MÉTODO DE EULER PARA EDO Y DE ORDEN SUPERIOR USANDO SCILAB 5.5
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 

EL VALOR DE PI USANDO EL MÉTODO MONTE CARLO EN FORTRAN, SCILAB 5.5 Y MATLAB

  • 1. Año de la Diversificación Productiva y del Fortalecimiento de la Educación UNIVERSIDAD NACIONAL DEL CALLAO FACULTAD DE CIENCIAS NATURALES Y MATEMÁTICA FÍSICA TEÓRICA COMPUTACIONAL II “EL VALOR DE PI USANDO EL MÉTODO MONTE CARLO EN FORTRAN Y SCILAB 5.5” MARCO ANTONIO ALPACA CHAMBA ESCUELA PROFESIONAL DE: FÍSICA PROGRAM IMPLICIT NONE REAL, INTEGER… 11 -06-2015
  • 2. Encontrar el valor de pi por el Método MONTE CARLO: USANDO FORTRAN TENEMOS: PROGRAM MONTE_PI INTEGER::S,L REAL :: X,Y,PI,N,R OPEN(UNIT=12,FILE='DENTRO.TXT',STATUS='UNKNOWN',ACTION='WRITE') OPEN(UNIT=13,FILE='FUERA.TXT',STATUS='UNKNOWN',ACTION='WRITE') PRINT*,'' PRINT*, '=====================================================================' PRINT*,' EL VALOR DE PI USANDO EL METHODMONTE CARLO' PRINT*,'================================================================== ====' PRINT*,'' PRINT*, 'INGRESAR EL NUMBER DE HISTORIAS:' READ(5,*) N PRINT*,'' PRINT*,('*',I=1,79) PRINT '(5X,"RESULTADOS COMPUTACIONALES")' PRINT*,('*',I=1,79) DO J=1,N R=1 IF (MOD(J,500)==0) THEN !DO WHILE (K<N+1) S=0 D=0 CALL RANDOM_SEED() END IF ENDDO DO L=1,N CALL RANDOM_NUMBER(X) CALL RANDOM_NUMBER(Y) RALEAT=SQRT(X**2+Y**2) IF(RALEAT<=(R**2)) THEN S=S+1 WRITE(12,7)X,Y ELSE D=D+1 WRITE(13,9)X,Y END IF ENDDO PI=4*S/N 7 FORMAT(2X,2F8.4) 9 FORMAT(2X,2F8.4) PRINT*,'EL NUMBER APROXIMADO DE PI ES:',PI PRINT*,'' STOP END PROGRAM
  • 3. USANDO SCILAB TENEMOS: A=read('DENTRO.txt',15654,2); x=A(:,1); y=A(:,2); B=read('FUERA.txt',4238,2); x1=B(:,1); y1=B(:,2); plot(x,y,'ro') plot(x1,y1,'b*') xlabel('coordenada aleatoria(X)','fontsize',4) ylabel('coordenada aleatoria (Y)','fontsize',4) title('EL VALOR DE PI USANDO MONTE CARLO','fontsize',5);
  • 4. program rng_estimate_pi implicit none integer,parameter:: NUM_DRAWS_TOTAL =1e7 integer::countDrawsInCircle =0,i real :: randomPosition (2) integer:: seedArray (16) call date_and_time(values=seedArray (1:8)) call date_and_time(values=seedArray (9:16)) call random_seed(put=seedArray) do i=1,NUM_DRAWS_TOTAL call random_number( randomPosition ) if((randomPosition(1)**2 + randomPosition(2)**2)<1.0) then countDrawsInCircle = countDrawsInCircle + 1 end if end do print*,'' print*,"el valor estimado de pi es:=", & 4.0*(real(countDrawsInCircle )/ real(NUM_DRAWS_TOTAL )) end program rng_estimate_pi
  • 5. USANDO MATLAB TENEMOS: rand('state',123) n = 5000; XY=rand(n,2)*2-1; isin=sum(XY.^2,2)<1; m=sum(isin); piestimate=4*m/n; pi; figure('color',[1,1,1]); plot(XY(isin,1),XY(isin,2),'b.'); axis equal; USANDO SCILAB TENEMOS: function [xy, isin, piest]=mcpi(n) xy = rand(n,2); xy = xy * 2 - 1;
  • 6. isin = sum(xy .^ 2, 2) < 1; m = sum(isin); piest = 4 * m/n; endfunction [xy,isin,piest]=mcpi(5000); plot(xy(isin,1),xy(isin,2),'b.'); mtlb_axis("equal"); disp('pi_estimado'); disp(piest);