25.06.2013 Views

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

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.

244 Unità di Programma<br />

FUNCTION f(x)<br />

! Funzione di cui si deve valutare la radice<br />

IMPLICIT NONE<br />

INTEGER, PARAMETER :: dp=KIND(1D0)<br />

REAL(KIND=dp) , INTENT(IN) :: x<br />

REAL(KIND=dp) :: f<br />

f = ((x-2.0_dp)*x+1.0_dp)*x-3.0_dp<br />

RETURN<br />

END FUNCTION f<br />

FUNCTION df(x)<br />

! Derivata della funzione argomento<br />

IMPLICIT NONE<br />

INTEGER, PARAMETER :: dp=KIND(1D0)<br />

REAL(KIND=dp), INTENT(IN) :: x<br />

REAL(KIND=dp) :: df<br />

df = (3.0_dp*x - 4.0_dp)*x + 1.0_dp<br />

RETURN<br />

END FUNCTION df<br />

L’output del programma così sviluppato è:<br />

n x f(x)<br />

==============================================<br />

0 4.0000000000000000 32.9999999999999982<br />

1 3.0000000000000000 9.0000000000000000<br />

2 2.4375000000000000 2.0368652343750000<br />

3 2.21303271631510<strong>95</strong> 0.2563633850614173<br />

4 2.1755549387214880 0.0064633614888132<br />

5 2.1745601006664458 0.00000447<strong>90</strong>680502<br />

6 2.1745594102933125 0.0000000000021574<br />

Radice della funzione: 2.1745594<br />

Valore della funzione: 0.0000000<br />

5.8 Argomenti delle Procedure<br />

5.8.1 L’attributo INTENT<br />

In <strong>Fortran</strong> è possibile (oltre ad essere buona regola di programmazione) specificare in che modo<br />

il parametro formale verrà adoperato nella procedura. In altre parole è possibile ”marcare” un<br />

parametro formale come parametro di ingresso, di uscita o di ingresso/uscita. Ciò può essere<br />

fatto a mezzo dell’attributo INTENT, il quale può assumere una delle seguenti forme:

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

Saved successfully!

Ooh no, something went wrong!