- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[sectionbodytext]the last line "mtpl(b,a)" means matrix b * matrix a[/sectionbodytext]
[sectionbodytext]absolutely,it is illegal b is 3*2,and a is 1*3. my question is [/sectionbodytext]
[sectionbodytext]why can it be Compiled Successfully[/sectionbodytext]
here is my simplified codes:
[fortran]module mat contains function mtpl(x,y) implicit none real:: x(:,:),y(:,:) real,allocatable:: mtpl(:,:) integer:: row_x,col_x,row_y,col_y !----------------------------------- row_x = ubound(x,1) col_x = ubound(x,2) row_y = ubound(y,1) col_y = ubound(y,2) !--------(1)------ allocate(mtpl(row_x,col_y)) mtpl = matmul(x,y) end function mtpl end module mat !---------------------------------------------------- program problem use mat implicit none real:: a(1,3)=(/1,2,3/) real:: b(3,2)=reshape((/1,2,3,4,5,6/),(/3,2/)) write(*,*) mtpl(b,a) !--------(2)------- end program problem[/fortran]
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are many things that are mathematical nonsense (or "illegal", as you say) that can be programmed in Fortran (or C, PL/I, etc.). The Fortran compiler does not know more than rudimentary mathematics. In particular, it does not know that mtpl is a matrix multiplication routine, that the two arguments have to conform, what "conform" means, etc. It is up to you to program checks for conformability, if you desire.
More generally, it is possible to write a syntactically correct Fortran program that happens to implement an incorrect calculation or even a faulty algorithm. That is why one has test problems and other checks to examine whether the program is performing correctly.
More generally, it is possible to write a syntactically correct Fortran program that happens to implement an incorrect calculation or even a faulty algorithm. That is why one has test problems and other checks to examine whether the program is performing correctly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your answer!
I know there's something wrong in my codes, and it exists some differences between compiler and me in understanding the codes. However, the Detailsof the problem is what I 'm mostconcerned about, if you want , please give me someProposal

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page