Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran, complex array with rank one

  1. Sep 19, 2009 #1
    I'm using the MATMUL command to multiplicate two arrays: array A is of rank one and has three complex elements, while array B is a 3x3 matrix with complex elements. However, the compilation is aborted because "the shapes of the array expressions do not conform". I'm pretty sure that the operation MATMUL(B,A) should yield a 3x1 array with complex elements, so I suspect that the expression defining array A isn't correct. Right now it looks like this:

    A=[0.e0+0.e0, 0.e0+0.e0, 1.e-29+0.e0]

    (I'm only interested in the real part of the last element for the moment.) Is this really the way to express a complex, rank one array?
  2. jcsd
  3. Sep 19, 2009 #2


    User Avatar
    Science Advisor

    You can't multiply an array of rank 1 by an array of rank 2.

    MATMAL(B,A) will work if B is rank 3x3 and A is rank 3x1, and the result will be rank 3x1
  4. Sep 20, 2009 #3
    That's strange, because this is what it says in the book NUMERICAL RECIPES IN FORTRAN 90: The Art of PARALLEL Scientific Computing

    I guess you're right since it doesn't work, but perhaps I'm misinterpreting the quoted text?
  5. Sep 20, 2009 #4


    User Avatar
    Science Advisor

    It may depend on what compiler you are using. I'm not sure. Did you try using the 3x1 matrix?
  6. Sep 20, 2009 #5
    Yes, I tried that before trying this method. It worked fine, but the problem is that in the same program, I want to be able to calculate the dot product of array A. I don't know how to do this if I define it as a 3X1 matrix.
  7. Sep 20, 2009 #6
    Ok, now I know exactly what is wrong, but not how to fix it. The relevant part of the code looks like this:


    The part that is wrong is the "c", because the command

    write(*,*) matmul(a,b)

    gives the correct output. I obviously have to define "c" properly, but

    real, complex(3,1) :: c

    doesn't do. Any suggestions?
  8. Sep 20, 2009 #7
    I think I solved the problem. Thanks anyway, sylas.
  9. Sep 20, 2009 #8


    User Avatar
    Science Advisor

    You're welcome. Please post the solution. I'm rusty on Fortran, and would like to know!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook