Total Tayangan Halaman

Selasa, 20 Januari 2015

Menghitung simpangan baku (deviasi standar) [CARA II, lebih ringkas]

real, allocatable:: X(:)

!membaca data dari file
OPEN(1, FILE='ABC.TXT', status='unknown')
read(1,*)n; allocate(X(n))
read(1,*) (x(i), i=1,n)
close(1)

!menghitung nilai rata-rata
total=0
do i=1,n; total = total + x(i); enddo
Xr = total/n

!menghitung jumlah (X-Xr)²
total2=0
do i=1,n; total2 = total2 + ( X(i) - Xr )**2; enddo

!menghitung S
S = sqrt(total2/n)

!menyimpan hasil perhitungan ke dalam file 'Hasil.txt'
open (2, file='HASIL.TXT', status='unknown')
write(2,*) 'Xr=', Xr
write(2,*) '============================'
WRITE(2,*) ' No    X    X-Xr     (X-Xr)²'
write(2,*) '============================'
do m=1,n;  write(2,'(i4, i5, f8.1, f10.2)') m, int(x(m)),  X(m)-Xr,  (X(m)-Xr)**2; enddo
write(2,*) '============================'
write(2,'(1x,A17,f9.2)') 'Jumlah --------->', total2
write(2,*) '============================'
write(2, '(1x,A2,f5.3)') 'S=',S
close(2)
print*, "SELESAI, silakan klik 2X file 'Hasil.TXT' "
read*  !berhenti, sampai ditekan enter
end

Tidak ada komentar:

Posting Komentar