- #1

kinbeat

- 2

- 0

**Hi, I'm dealing with an exam problem (which i have 8 days to solve, with no outside help limitations), which is to write a fortran95 program that solves linear systems.**

the first part asks to find the determinant of a NxN matrix with the laplace expansion, implementing it as a recursive function.

this is what I've done so far

module prec

integer, parameter :: rk= selected_real_kind(6)

end module prec

module lap

use prec

implicit nonecontains

recursive function det(a) result (d)

real(kind=rk), intent(in), dimension(:,:) :: a

real(kind=rk), allocatable,dimension(:,:) :: b

real(kind=rk) :: d

integer ::i,n

n=0

b(1:i-1,1:n) = a(1:i-1,2:n)

b(i:n,1:n) =a(i+1:n,2:n)

if (size(a) > 2) then

do i=1,n

d= ((-1)**(i+1))*a(i,1)*det(b)

end do

else

d = a(1,1)*a(2,2)-a(1,2)*a(2,1)

end if

end function det

end module lap

program sistema

use lap

real(kind=rk), allocatable, dimension(:,:) :: c

real(kind=rk) :: z

integer ::j,m

print*,'Inserisci la dimensione della matrice'

read*,m

allocate(c(m,m))

print*, 'inserisci i coefficienti della matrice'

read*, c

do j=1,m

print*,c(j,:)

end do

z=det(c)

print*, z

end program sistema

the first part asks to find the determinant of a NxN matrix with the laplace expansion, implementing it as a recursive function.

this is what I've done so far

module prec

integer, parameter :: rk= selected_real_kind(6)

end module prec

module lap

use prec

implicit nonecontains

recursive function det(a) result (d)

real(kind=rk), intent(in), dimension(:,:) :: a

real(kind=rk), allocatable,dimension(:,:) :: b

real(kind=rk) :: d

integer ::i,n

n=0

b(1:i-1,1:n) = a(1:i-1,2:n)

b(i:n,1:n) =a(i+1:n,2:n)

if (size(a) > 2) then

do i=1,n

d= ((-1)**(i+1))*a(i,1)*det(b)

end do

else

d = a(1,1)*a(2,2)-a(1,2)*a(2,1)

end if

end function det

end module lap

program sistema

use lap

real(kind=rk), allocatable, dimension(:,:) :: c

real(kind=rk) :: z

integer ::j,m

print*,'Inserisci la dimensione della matrice'

read*,m

allocate(c(m,m))

print*, 'inserisci i coefficienti della matrice'

read*, c

do j=1,m

print*,c(j,:)

end do

z=det(c)

print*, z

end program sistema

but the compiler gives me this error:

error 112, reference to undefined variable, array element of function result (/undef)

LAP!DET - in file matrice.f95 at line 18 [+00aa]

main - in file matrice.f95 at line 51 [+0521]

what am i not seeing?