SHOW:
|
|
- or go back to the newest paste.
| 1 | program sinus | |
| 2 | ||
| 3 | ! define variables | |
| 4 | implicit none | |
| 5 | double precision :: f, fac, pi, r | |
| 6 | integer :: m, n, i | |
| 7 | pi = acos(-1.0) | |
| 8 | ||
| 9 | !initialize sin(0)=0 | |
| 10 | f=0 | |
| 11 | ||
| 12 | ! initialize inner loop count i | |
| 13 | i=1 | |
| 14 | ||
| 15 | ! initialize 0!=1 | |
| 16 | fac=1 | |
| 17 | ! calculate (m=1,2,...,10) | |
| 18 | DO m=0,10 | |
| 19 | DO n=i,2*m+1 | |
| 20 | ||
| 21 | fac=fac*DBLE(n) | |
| 22 | i=i+1 | |
| 23 | ||
| 24 | END DO | |
| 25 | f=f +((-1)**(m)) * (pi/4)**(2*m+1) / fac | |
| 26 | - | print*, fac |
| 26 | + | |
| 27 | print*, 'm =',m,' ',f | |
| 28 | ||
| 29 | END DO | |
| 30 | ||
| 31 | !real value of sinus at pi/4 | |
| 32 | r = sin(pi/4) | |
| 33 | print*, 'Der echte Wert der Sinusfunktion an der Stelle x=pi/4:' | |
| 34 | print*,' ', r | |
| 35 | ||
| 36 | !compare end f with real value of sinus at pi/4 | |
| 37 | print*, 'Der Unterschied zwischem dem echten Wert und dem errechneten Wert:' | |
| 38 | print*, ' ',(r-f) | |
| 39 | ||
| 40 | print*, 'Funfact: Meine innere Schleife wurde', i-1, 'mal durchlaufen.' | |
| 41 | end program |