02.05.2014 Views

Patrick Corde & Anne Fouilloux

Patrick Corde & Anne Fouilloux

Patrick Corde & Anne Fouilloux

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Durée de vie des identificateurs 169<br />

program newton<br />

double precision :: valeur = 50.d0<br />

double precision :: tolerance<br />

double precision :: racine, x<br />

tolerance = 1.0d-1<br />

x = racine( valeur, tolerance )<br />

print ’("Racine de ",f5.1," = ", d16.8)’, valeur, x<br />

tolerance = 1.0d-6<br />

x = racine( valeur, tolerance )<br />

print ’("Racine de ",f5.1," = ", d16.8)’, valeur, x<br />

end program newton<br />

function racine( valeur, tol )<br />

double precision :: valeur, tol<br />

double precision :: racine<br />

double precision :: x = 1.0d0, x_prev<br />

integer<br />

:: nb_iterations<br />

nb_iterations = 0<br />

do<br />

nb_iterations = nb_iterations + 1<br />

x_prev = x<br />

x = 0.5 * (x_prev + valeur/x_prev)<br />

if ( abs(x-x_prev)/x < tol ) exit<br />

end do<br />

print *,"Nombre d’itérations = ", nb_iterations<br />

racine = x<br />

end function racine<br />

INSTITUT DU DÉVELOPPEMENT<br />

ET DES RESSOURCES<br />

EN INFORMATIQUE SCIENTIFIQUE<br />

Cours langage Fortran – 27 janvier 2006<br />

<strong>Patrick</strong> <strong>Corde</strong> et <strong>Anne</strong> <strong>Fouilloux</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!