!Este programa es el mismo que el de Traces.f95 pero con la traza sacada en forma de módulo module utilities implicit none contains real function trace (A) real , intent (in) :: A ( 0: , 0:) integer :: M integer :: i real :: S M = size ( A , dim =1 ) S=0 do i = 0 , M-1 S = S + A (i, i) end do trace = S end function end module Program traces use utilities implicit none real , allocatable :: A (:,:), B(:,:), C(:,:) integer :: M,N integer :: i, j, o, p, k real :: S, T S=0 do M=1 , 10 allocate ( A ( 0 : M , 0 : M ) ) forall ( i = 0 : M , j = 0 : M ) A (i,j) = (i/real (M) ) **j S= S + trace (A) write (*,*) "trace 1 is = ", S deallocate (A) end do !A partir de aquí son los otros dos apartados que no me salen D: ! T=0 ! do N=1,5 ! allocate ( B ( 0 : N , 0 : N ) ) ! forall ( o = 0 : N , p = 0 : N ) B (o,p) = (o/real (N) ) **(2*p) ! T= T + trace (B) ! write (*,*) 'trace 2 is =' , T ! deallocate (B) ! end do ! M=4 ! allocate ( A ( 0 : M , 0 : M ) ) ! forall ( i = 0 : M , j = 0 : M ) A (i,j) = (i/real (M) ) **(k*j) ! C (i = 0 : M , j = 0 : M ) = (0:0) ! do k=1,5 ! C (i = 0 : M , j = 0 : M ) = (C (i = 0 M , j = 0 : M )) + A (:,:) ! end do ! write (*,*) 'trace 3 is =' , trace (C) end program