Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

LOG function on a 2x2 matrix.

83 views
Skip to first unread message

Giulio Petrucci

unread,
Jul 29, 2011, 6:24:19 AM7/29/11
to
Hi there,

I'm following the "Fortran 95/2003 for Scientists and Engineers"
textbook and I got at the WHERE statement. The book present the
following sample:

WHERE ( value> O. )
logval LOG(value)
ELSEWHERE
logval = -99999.
END WHERE

whith 'logval' and 'value' two matrices of the same dimension. I copied
the example "as is" in a .f90:

PROGRAM wheretest
implicit none
real, dimension(2,2) :: matrix
real, dimension(2,2) :: log

matrix(1,1) = 23
matrix(1,2) = -1
matrix(2,1) = -1
matrix(2,2) = 17

WHERE (matrix > 0.)
log = LOG(matrix)
ELSEWHERE
log = -99999.
END WHERE
END PROGRAM wheretest

I have the following two compilation errors:

D:\>gfortran-4.exe wheretest.f90
wheretest.f90:19.15:

log = LOG(matrix)
1
Warning: Extension: REAL array index at (1)
wheretest.f90:19.15:

log = LOG(matrix)
1
Error: Array index at (1) is an array of rank 2

I have the following list of newbie-questions:
1. is there any reference where I can search for such error messages to
get what is happening?
2. I noticed that changing the matricex into one-dimensional arrays
everything works fine... is it a difference between f90 and f95? Could
you link me any reference to this issue?

Thanks,
Giulio

p.s. I'm using this compiler on Cygwin on WinXP:

D:>gfortran-4.exe --version
GNU Fortran (GCC) 4.3.2 20080827 (beta) 2
Copyright (C) 2008 Free Software Foundation, Inc.

--

Joseph Huber

unread,
Jul 29, 2011, 6:49:37 AM7/29/11
to
Giulio Petrucci wrote:

Short of reading the standard document - but:
LOG() is an intrinsic function , but the wheretest program is defining an
array variable with the same name.
Change the definition of log to something else like mlog.

Remove NOREPLY. from Email address.
Joseph Huber, http://www.huber-joseph.de

Giulio Petrucci

unread,
Jul 29, 2011, 8:04:20 AM7/29/11
to
Hi Joseph,

On 7/29/2011 12:49 PM, Joseph Huber wrote:
> LOG() is an intrinsic function , but the wheretest program is defining an
> array variable with the same name.
> Change the definition of log to something else like mlog.

OMG... Fortran is case insensitive!
I completely forgot this issue. :-/

thanks,
Giulio

--

Ken Fairfield

unread,
Jul 29, 2011, 12:44:55 PM7/29/11
to
^^^^^
Er...rather, *feature*! :-)

No, I won't start the which-is-better argument...

-Ken

glen herrmannsfeldt

unread,
Jul 30, 2011, 2:42:41 AM7/30/11
to
Giulio Petrucci <sis...@nonono.boh> wrote:

> I'm following the "Fortran 95/2003 for Scientists and Engineers"
> textbook and I got at the WHERE statement. The book present the
> following sample:

> WHERE ( value> O. )
> logval LOG(value)
> ELSEWHERE
> logval = -99999.
> END WHERE

> whith 'logval' and 'value' two matrices of the same dimension. I copied
> the example "as is" in a .f90:

I presume you want the log element by element. The exponential (exp) of
a matrix can be done, though not so obviously its inverse.

I have a calculator that will do matrix exponential
(not element by element).

-- glen

Arjan

unread,
Jul 31, 2011, 6:32:28 AM7/31/11
to
I guess you used LOG just for the sake of showing a syntactic problem
and not for any particular interest in taking the LOG of a matrix.

Just for in case you really want to take the LOG of a matrix:
-> Do you really want to have the LOG of every element?
Or are you looking for a matrix that gives you the infinitesimal rate
of change
needed during integration to yield "MATRIX"?

If you e.g. have a vector equation d/dt X_i = A_ij X_j with unknown
matrix A,
but with known matrix B such that X(t)_i = B_ij X(t=0)_j,
then you would be looking for a different type of "LOG":
-transform the matrix to eigen-system,
-take the LOG of the eigenvalues, and
-transform back to your original system.

Regards,


A.

0 new messages