Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions RESUL.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lista2.f90
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Binary file added lista3
Binary file not shown.
28 changes: 28 additions & 0 deletions lista3.f90
Original file line number Diff line number Diff line change
@@ -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
59 changes: 57 additions & 2 deletions methods.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 3 additions & 0 deletions sistemaM.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
4
1 2 3 4
1 2.5 3.5 4.3