In file lab12A.f95:56
RESULT = MATMUL(array, array2)
1
Error: Incompatible ranks 0 and 2 in assignment at (1).
There is what the statement looks like in my file:
DO irows = 1, ROWS
RESULT = MATMUL(array, array2)
WRITE(*,*)irows, RESULT
END DO
How do i fix it? Please help.
Fix the problem... :)
You don't show the size declarations for either argument to the MATMUL
call, but the result has to have the size at least that of that required
for the conformance of matrix multiplication.
If a1, a2 are mxn and nxk, then matmul(a1,a2) will be mxk
The error indicates you didn't allocate an array for RESULT at all (rank 0)
--
What are the dimensions for RESULT, array, and array2?
Also, why is RESULT independent of irows, but computed
inside the loop?
> There is what the statement looks like in my file:
> DO irows = 1, ROWS
> RESULT = MATMUL(array, array2)
> WRITE(*,*)irows, RESULT
> END DO
> How do i fix it? Please help.
What are you actually trying to do?
-- glen
---
frmsrcurl: http://compgroups.net/comp.lang.fortran/Problem-with-Matmul
> I'm trying to create a MULMAT statement, but i don't know why i keep
getting this error.
See the other posts. Realize
1. There is no such thing as a "matmul statement" (I assume mulmat was a
typo for matmul, but that isn't the point). MATMUL is just a function
like many other finctions; it is not a distinct statement. What you have
is an assignment statement. In fact...
2. It appears that your problem is not related to MATMUL at all, but
rather to the assignment. The MATMUL part is fine. What is not fine is
that you apparently are trying to assign the result of MATMUL to a
scalar.The result isn't a scalar and you can't assign it to one.
3. Show your declarations. They are very important. It is quite common
for problems to be in the declarations instead of the executable
statements. That appears likely to be the case here. People are just
having to guess that you didn't declare result to be an array because
that is suggested by the erro rmessage. Diagnosing computer code can be
hard enough even when one has the code to look at. It is much harder
when one has to diagnose problems in code that isn't even shown - such
as the declarations here.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
This code is no help. What are your declarations?
But here is a simple similar program if you are just trying to see how
to use matmul function of fortran
program matmultest
implicit none
double precision :: array(3,5), array2(5,3),result(3,3)
integer :: irows,icols,ii,j
do irows=1,5
do icols=1,3
array(icols,irows)=(irows-icols)*0.5d0
array2(irows,icols)=(irows-icols)*1.0d0
end do
end do
write(*,'(a)') 'Array :'
do ii=1,3
write(*,'(5f12.6)') (array(ii,j),j=1,5)
end do
write(*,'(a)') 'Array2 :'
do ii=1,5
write(*,'(3f12.6)') (array2(ii,j),j=1,3)
end do
result = MATMUL(array, array2)
write(*,'(a)') 'Result :'
do ii=1,3
write(*,'(3f12.6)') (result(ii,j),j=1,3)
end do
end program
This will produce this output
Array :
0.000000 0.500000 1.000000 1.500000 2.000000
-0.500000 0.000000 0.500000 1.000000 1.500000
-1.000000 -0.500000 0.000000 0.500000 1.000000
Array2 :
0.000000 -1.000000 -2.000000
1.000000 0.000000 -1.000000
2.000000 1.000000 0.000000
3.000000 2.000000 1.000000
4.000000 3.000000 2.000000
Result :
15.000000 10.000000 5.000000
10.000000 7.500000 5.000000
5.000000 5.000000 5.000000
If that is your intention, look at this program along with all the
previous comments.
cheers