NueclearSnake
Messages postés3Date d'inscriptionmercredi 21 février 2007StatutMembreDernière intervention10 novembre 2007
-
21 févr. 2007 à 23:41
satan59850
Messages postés1Date d'inscriptionlundi 11 octobre 2010StatutMembreDernière intervention11 octobre 2010
-
11 oct. 2010 à 20:36
bonjour à tous,
je suis tout nouveau ici et je programme en fortran, je dois faire la résolution de Ax=b par la méthode de gauss, mais j'ai un gros problème, mon programme compile mais ne donne pas la bonne solution;
Pouvez vous m'aider???
Merci d'avance
module resolutionmod
contains
function resolution(a,b)
implicit none
real*8,dimension(:,:),intent(inout)::a
real*8,dimension(:),intent(inout)::b
real*8,dimension(:),allocatable::x
real*8,dimension(size(b))::resolution
integer:: i,j,k,l,imax,n
real*8::s,pivot, alpha,xx
n=size(b)
allocate(x(n))
do i=1,n
imax=i
pivot=abs(a(i,i))
do k=i+1,n
if (abs(a(k,i)) > pivot) then
pivot=abs(a(k,i))
imax=k
endif
end do
print*, 'le pivot est',a(imax,i)
!j'attribue a pivot la valeur de a(imax,imax) sans valeur absolue
pivot=a(imax,i)
!j echange les lignes si il y a lieu
if (i.ne.imax) then
do l=1,n
xx=a(i,l)
a(i,l)=a(imax,l)
a(imax,l)=xx
end do
xx=b(i)
b(i)=b(imax)
b(imax)=xx
end if
!je soustrais les deux lignes
do k=i+1,n
if (a(k,i) .ne. 0) then
alpha=pivot/(a(k,i))
do j=i,n
a(k,j)=alpha*a(k,j)
a(k,j)=a(k,j)-a(i,j)
end do
!et les resultats
b(k)=alpha*b(k)-b(i)
endif
end do
end do
!verifier si on peut resoudre le pb sans conditions initiales
if (a(n,n).ne. 0) then
x(n)=b(n)/a(n,n)
end if
do i=n-1,1,-1
if (a(i,i).ne.0) then
s=0
do j=i+1,n
s = s + a(i,j)*x(j)
end do
x(i)=(b(i) - s)/a(i,i)
else
print*,'resolution impossible sans conditions initiales'
end if
end do
resolution=x
end function resolution
end module resolutionmod