Created
January 3, 2012 04:15
-
-
Save taiar/1553449 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program entrada | |
! quantidade de dados da entrada, indices | |
integer n, i | |
! vetor de abcissas, vetor de ordenadas | |
real x(99), y(99) | |
! coeficiente de inclinacao da reta, termo independente | |
real a, b | |
! somatorio de Xi, somatorio de Yi, somatorio de XiYi, somatorio do | |
! quadraro de Xi | |
real sX, sY, sXY, sXX | |
write(*,*) "Quantidade de pontos da entrada:" | |
read(*, ‘(i2)’) n | |
write(*,*) | |
open(10, file='entrada', status='old') | |
! descreve o formato do arquivo de entrada | |
101 format(f10.5,2x,f10.5) | |
! faz leitura do arquivo de entrada e coloca nos vetores de ordenadas | |
! e abcissas | |
do i = 1, n | |
read(10, 101) x(i), y(i) | |
enddo | |
sX = 0 | |
sY = 0 | |
sXY = 0 | |
sXX = 0 | |
! calcula somatorios utilizados no Método dos Quadrados Mínimos | |
do i = 1, n | |
sX = sX + x(i) | |
sY = sY + y(i) | |
sXX = sXX + x(i) * x(i) | |
sXY = sXY + x(i) * y(i) | |
enddo | |
! formula do coeficiente de inclinacao 'a' | |
a = (((sX * sY) - (float(n) * sXY)) / ((sX * sX) - (float(n) * sXX))) | |
! formula do termo independente 'b' | |
b = ((sY - (a * sX)) / float(n)) | |
! imprime o resultado da Regressão Linear | |
write(*,102), a | |
write(*,103), b | |
write(*,*) | |
write(*, 104), a, b | |
! formatos de impressao da saída | |
102 format('Valor de a = ',f10.5) | |
103 format('Valor de b = ',f10.5) | |
104 format('Da reta: y = ', f10.5,‘x + ‘,f10.5) | |
end program entrada |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment