Total Tayangan Halaman

Selasa, 20 Januari 2015

Menghitung simpangan baku (deviasi standar) [CARA I]


real, allocatable:: X(:), X_Xr(:) , X_Xr2(:)
real jumlah

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

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

!menghitung nilai X-Xr
do i=1,n
   X_Xr(i) = X(i)-Xr
enddo

!menghitung nilai (X-Xr)²
do k=1,n
   X_Xr2(k) = X_Xr(k)**2
enddo

!menghitung jumlah dari (X-Xr)²
jumlah=0
do j=1,n
   jumlah = jumlah + X_Xr2(j)
enddo

!menghitung S
S = sqrt(jumlah/n)

!menyimpan hasil perhitungan ke dalam file
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,10) m, int(x(m)),  X_Xr(m),  X_Xr2(m)
enddo
10 format(i4, i5, f8.1, f12.2)
write(2,*) '============================'
write(2,*) 'Jumlah           ', jumlah
write(2,*) '============================'
write(2,20) 'S=',S
20 format(1x,A2, f5.3)
close(2)
write(*,*) 'SELESAI, silakan klik 2X file Hasil.TXT'
read*

end

Tidak ada komentar:

Posting Komentar