MVLib - Short Writeup - Version 4.0
Example Number 46 - Pi-grec estimation
This example shows how to estimate the value of Pi-grep using a Montecarlo-based method. The loop in the main program extracts two random coordinate and counts the number of points falling inside the circle. Being the ratio of "good points" proportional to the ratio of the areas, the value og Pi-grec is estimated.
The fortran code is available here and the complete script running the code is available here.
Previous Example List of Examples Next Example
MVLib Home Page
	implicit none
	real x,y,acaso,ngol ; integer i,ntiri ; character title*40 
	call graphiclayout
	ntiri=100 ; ngol=0
	do i=1,ntiri
	   x=acaso(x) ; y=acaso(y)
	   call disegnapunto(x,y)
	   if (x**2+y**2.lt.1) ngol=ngol+1
	enddo
	write(title,'(a,f4.2)') 'Stima di pi greco: ',4*ngol/ntiri
	call displayplot(' ',' ',title)
        end

	subroutine disegnapunto(x,y)
	implicit none
	real x,y
	call pallocchetto ((x+1)/2,(y+1)/2,0.005,9)
	return
	end

	subroutine graphiclayout
	call mvsetflags('Palette di colori',8.0)
	call mvsetflags('Colore Titoli',6.0)
	call mvsetflags('Random seed',3388148907.0)
	call scrivisulplot(' ',0.85,0.05)
	call set (0.0,1.0,0.0,1.0,-1.0,1.0,-1.0,1.0,1)
	call pallocchetto (0.5,0.5,0.5,8)
	call linea(0.0,-1.0,0.0,1.0)
	call linea(-1.0,0.0,1.0,0.0)
	return
	end