For Programmers: Free Programming Magazines  


Home > Archive > Fortran > December 2006 > Determinant of upper traingular arrays









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Determinant of upper traingular arrays
taif.man@googlemail.com

2006-12-13, 4:18 pm

I am trying to find the determinant of an upper traingular matrix
stored rowwise in a vector. I know that the determinant of an upper
traingular matrix is the product of its diagonal elements, which I
tried to implement -in Fortran 77- in this way:

suppose an upper triangluar matrix (N X N) is stored rowwise in a
vector v(N*(N+1)/2)

i=N+1
det=1.d0 >>> determinant
do j=1,N
i = i - j
det = det * v(i)
enddo
But for some reasons the index i goes to negative numbers !

So, can you suggest any alternative idea.

Best,
TA

Ian Bush

2006-12-13, 4:18 pm

taif.man@googlemail.com wrote:

> I am trying to find the determinant of an upper traingular matrix
> stored rowwise in a vector. I know that the determinant of an upper
> traingular matrix is the product of its diagonal elements, which I
> tried to implement -in Fortran 77- in this way:
>
> suppose an upper triangluar matrix (N X N) is stored rowwise in a
> vector v(N*(N+1)/2)
>


Think about the line below - is this really the starting point that you
want ?

> i=N+1
> det=1.d0 >>> determinant
> do j=1,N
> i = i - j
> det = det * v(i)
> enddo
> But for some reasons the index i goes to negative numbers !
>
> So, can you suggest any alternative idea.
>


As far as I am concerned the only way is up !

i = 0
det = 1.0d0 ! But kinds are SO much nicer
Do j = 1, n
i = i + j
det = det * v( i )
End Do

( untested )

Ian

john2

2006-12-13, 4:18 pm


> i=N+1
> det=1.d0 >>> determinant
> do j=1,N
> i = i - j
> det = det * v(i)
> enddo



Try

> i = i - 1


in line 4

john2



Terence

2006-12-14, 4:13 am

For a vectorised upper triangular Matrix M, to calculate the
determinant, the first "row" of vector A is length N and you need the
first value M(1,1), the next is length N-1 and you need the first
values again M(2,2) and so on,
So:-
D=0.0
I=1
do J=1,N
D=D + A(I)
I=I+N-J
enddo

robin

2006-12-15, 7:06 pm

taif.man@googlemail.com wrote in message <1166008706.974490.199760@n67g2000cwd.googlegroups.com>...
>I am trying to find the determinant of an upper traingular matrix
>stored rowwise in a vector. I know that the determinant of an upper
>traingular matrix is the product of its diagonal elements, which I
>tried to implement -in Fortran 77- in this way:
>
>suppose an upper triangluar matrix (N X N) is stored rowwise in a
>vector v(N*(N+1)/2)
>
> i=N+1


The initial value of i should be 1+N*(N-1)/2 which is the number
of elements in the array, plus 1.

> det=1.d0 >>> determinant
> do j=1,N
> i = i - j
> det = det * v(i)
> enddo
>But for some reasons the index i goes to negative numbers !
>
>So, can you suggest any alternative idea.



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com