diff --git a/RESUL.txt b/RESUL.txt index bc4950e..ad94420 100644 --- a/RESUL.txt +++ b/RESUL.txt @@ -1,6 +1,3 @@ - 5.00000000 -4.00000000 1.00000000 0.00000000 - -4.00000000 6.00000000 -4.00000000 1.00000000 - 1.00000000 -4.00000000 6.00000000 -4.00000000 - 0.00000000 1.00000000 -4.00000000 5.00000000 - 5.79999876 10.1999979 10.7999983 7.19999886 - 0.00000000 + 1.00000000 2.00000000 3.00000000 4.00000000 + 1.00000000 2.50000000 3.50000000 4.30000019 + 0.100000381 1.09000015 diff --git a/lista2.f90 b/lista2.f90 index 84346e5..8164816 100644 --- a/lista2.f90 +++ b/lista2.f90 @@ -1,7 +1,7 @@ include 'methods.f90' program lista2 - integer n, i, j + integer n, m, i, j real, allocatable, dimension(:) :: b, x real, allocatable, dimension(:,:) :: a, d, c real lambda diff --git a/lista3 b/lista3 new file mode 100755 index 0000000..bdfdd20 Binary files /dev/null and b/lista3 differ diff --git a/lista3.f90 b/lista3.f90 new file mode 100644 index 0000000..7cf2e37 --- /dev/null +++ b/lista3.f90 @@ -0,0 +1,28 @@ +include 'methods.f90' + +program lista3 + integer n, i, j + real, allocatable, dimension(:) :: b, x, y + real, allocatable, dimension(:,:) :: a, d, c + real lambda + + ! abertura do arquivo sistema.txt e leitura + open (1, file='sistemaM.txt', status='old', action='read') + read(1,*) n + allocate(x(n)) + read(1,*) ( x(j) , j= 1 , n) + + allocate(y(n)) + read(1,*) ( y(i) , i= 1 , n) + close(1) + + allocate(b(2)) + call minimosQuadrados(b, x, y, n) + + open(2, file='RESUL.txt', status='replace') + write(2,*) (x(j), j=1, n) + write(2, *) (y(i), i=1, n) + write(2, *) (b(i), i=1, 2) + close(2) + +end program lista3 \ No newline at end of file diff --git a/methods.f90 b/methods.f90 index f9b9695..1f7d02d 100644 --- a/methods.f90 +++ b/methods.f90 @@ -450,7 +450,7 @@ subroutine powerMethod(a, x, n, tol, lambda) subroutine jocobi(a, x, n, tol, lambda) - integer :: n, i, j, k, tol, vi, vj + integer :: n, i, j, k, vi, vj real :: a(n,n), tol, x(n,n), lambda(n,n), maior x = 0.0 @@ -464,13 +464,68 @@ subroutine jocobi(a, x, n, tol, lambda) maior = 0.0 do i=1, n do j=(i+1), n - if (abs(a(i,j)) >= maior) + if (abs(a(i,j)) >= maior) then maior = abs(a(i,j)) vi = i vj = j + end if end do end do ! FALTA 2.2, 3 e 4 do slide do professor ! PREGUICA DE PENSAR NO ALGORITMO DE 2.2 end do end subroutine + +subroutine minimosQuadrados(b, x, y, n) + integer n, i, j + real b(2), x(n), y(n), a(2,2), soma, c(2), aI(2,2), det + + b = 0.0 + soma = 0.0 + + do i=1, n + soma = soma + 1 + end do + a(1,1) = soma + + soma = 0.0 + do i=1, n + soma = soma + x(i) + end do + a(2,1) = soma + a(1,2) = soma + + soma = 0.0 + do i=1, n + soma = soma + (x(i))**2 + end do + a(2,2) = soma + + soma = 0.0 + do i=1, n + soma = soma + y(i) + end do + c(1) = soma + + soma = 0.0 + do i=1, n + soma = soma + x(i)*y(i) + end do + c(2) = soma + + det = a(1,1)*a(2,2) - (a(1,2)*a(2,1)) + if (det == 0) then + STOP + end if + aI(1,1) = a(2,2)/det + aI(1,2) = -a(1,2)/det + aI(2,1) = -a(2,1)/det + aI(2,2) = a(1,1)/det + + call multiplicaVetorMatriz(aI, c, b, 2) + write(*,*) a + write(*,*) c + write(*,*) b + + +end subroutine \ No newline at end of file diff --git a/sistemaM.txt b/sistemaM.txt new file mode 100644 index 0000000..cf0d4c4 --- /dev/null +++ b/sistemaM.txt @@ -0,0 +1,3 @@ +4 +1 2 3 4 +1 2.5 3.5 4.3 \ No newline at end of file