Q1:about matmul(A,B). HELP!!!

Q1:about matmul(A,B). HELP!!!

Hi,

After evaluating the IVF, I love it and decide to give up the matlab. However, I really need somebody help me to make clear of my questions. One is about matmul(A,B). I define two arrays

real :: A(1,5), B(5,1)

then A=1;B=2

Now if I multiply the array A and the array B by using matmul(A,B), the result will be a array (result array) whose dimension is (1,1). Thus there is only one cell in the result array with a REAL value.

Here is my question. I want to define another real-type variable 'c' and set the value of 'c' equals to the cell value of the result array above. I tried

real :: c=0
c=matmul(A,B)

However, I get an error message, "error #6366: The shapes of the array expressions do not conform". I know the reason because a real variable can not equal to an array. But my question is how can I do this? I mean when I have a (1,1) array and I want to set the value of the only cell in this array to a real variable, how can I do this?

Thanks very much.

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

Quoting - yingwu
Hi,

After evaluating the IVF, I love it and decide to give up the matlab. However, I really need somebody help me to make clear of my questions. One is about matmul(A,B). I define two arrays

real :: A(1,5), B(5,1)

then A=1;B=2

Now if I multiply the array A and the array B by using matmul(A,B), the result will be a array (result array) whose dimension is (1,1). Thus there is only one cell in the result array with a REAL value.

Here is my question. I want to define another real-type variable 'c' and set the value of 'c' equals to the cell value of the result array above. I tried

real :: c=0
c=matmul(A,B)

However, I get an error message, "error #6366: The shapes of the array expressions do not conform". I know the reason because a real variable can not equal to an array. But my question is how can I do this? I mean when I have a (1,1) array and I want to set the value of the only cell in this array to a real variable, how can I do this?

Thanks very much.

real :: d(1,1),c, A(1,5), B(5,1)
equivalence (d(1,1),c)
A=1
B=2
d=matmul(A,B)
Print *, c

Hi,

I always use:

program mymatmul
real(kind=4) :: a(1,5),b(5,1),c
a=1.
b=2.
c=maxval(matmul(a,b))
end program mymatmul

Kind regards, Niels H. Veldhuijzen Zutphen, The Netherlands

Quoting - anthonyrichards

Quoting - yingwu
Hi,

After evaluating the IVF, I love it and decide to give up the matlab. However, I really need somebody help me to make clear of my questions. One is about matmul(A,B). I define two arrays

real :: A(1,5), B(5,1)

then A=1;B=2

Now if I multiply the array A and the array B by using matmul(A,B), the result will be a array (result array) whose dimension is (1,1). Thus there is only one cell in the result array with a REAL value.

Here is my question. I want to define another real-type variable 'c' and set the value of 'c' equals to the cell value of the result array above. I tried

real :: c=0
c=matmul(A,B)

However, I get an error message, "error #6366: The shapes of the array expressions do not conform". I know the reason because a real variable can not equal to an array. But my question is how can I do this? I mean when I have a (1,1) array and I want to set the value of the only cell in this array to a real variable, how can I do this?

Thanks very much.

real :: d(1,1),c, A(1,5), B(5,1)
equivalence (d(1,1),c)
A=1
B=2
d=matmul(A,B)
Print *, c

I'd prefer not to use equivalence:

real :: d(1,1),c, A(1,5), B(5,1)
A=1
B=2
d=matmul(A,B)
c = d(1,1)
Print *, c

Leave a Comment

Please sign in to add a comment. Not a member? Join today