array element (matrix) question
Author |
Message |
PCAT #1 / 6
|
 array element (matrix) question
HI, I have a question about how to simulaneously compare two matrices. Ex A(2,3)=[1 1 2] [ 2 1 0] B(2,3)=[3 0 3] [2 1 2] HOw to make a statement to compare all the elements of A and B? If (All elements of A <= all elements of B) then .... else .... I know there is a transformational Intrinsic Function called "all", also there is where elsewhere end where but I just know that All (matrix), the matrix should be logical array. what can I do? and the "where " above only considers element-by-element, not all element of the matrix. Also can anyone suggest some good readings or books about F90/95 and mention more about the matrices or array calculation? I have a book of fortran 90/95 for scientists and Engineers by Stephen J Chapman. But it seems not enough for me. Thank you very much.
|
Tue, 28 Oct 2008 05:25:21 GMT |
|
 |
Richard E Mai #2 / 6
|
 array element (matrix) question
Quote:
> HOw to make a statement to compare all the elements of A and B? > If (All elements of A <= all elements of B) then ... > I know there is a transformational Intrinsic Function called "all",
Yes, you are on the right track there. Quote: > but I just know that All (matrix), the matrix should be logical array. > what can I do?
Many operations on arrays are elemental, that is they operate on each element of the array and give an array result. This includes the relational operations like "<=". Thus A<=B gives a logical array, each element of which compares the corersponding element of A and B. So what you want is if (all(A<=B)) then ... Quote: > I have a book of Fortran 90/95 for scientists and Engineers by Stephen > J Chapman.
Not my favorite book. :-( But I'm not sure a book will quite give the right kind of insights to help much with writing array expressions like this. Anyway, if there is a book that helps much with that, I don't know of it. I think it helps more to ask a few questions like this and see the ways that people use the array intrinsics and operations. After seeing a few examples like that, you might be better able to pick it up. Though maybe someone else has better ideas on how to teach such things than I do. -- Richard Maine | Good judgment comes from experience; email: my first.last at org.domain| experience comes from bad judgment. org: nasa, domain: gov | -- Mark Twain
|
Tue, 28 Oct 2008 05:40:58 GMT |
|
 |
PCAT #3 / 6
|
 array element (matrix) question
Hi Richard, It works! I am looking for some useful books of fortran programming. Would you please recommend some books for me? Thank you very much.
|
Tue, 28 Oct 2008 06:26:50 GMT |
|
 |
Richard E Mai #4 / 6
|
 array element (matrix) question
Quote:
> It works! I am looking for some useful books of fortran programming. > Would you please recommend some books for me? Thank you very much.
I'm personally fond of Metcalf&Reid, particularly as a first book. It is relatively short and concise, which helps get you going, and I think it has a clear writing style. There are arguments for supplementing it with something more comprehensive, but I think it is at least one of the books that should be on a Fortran programmer's shelf. -- Richard Maine | Good judgment comes from experience; email: my first.last at org.domain| experience comes from bad judgment. org: nasa, domain: gov | -- Mark Twain
|
Tue, 28 Oct 2008 06:49:22 GMT |
|
 |
John Harp #5 / 6
|
 array element (matrix) question
Quote:
>> It works! I am looking for some useful books of fortran programming. >> Would you please recommend some books for me? Thank you very much. >I'm personally fond of Metcalf&Reid, particularly as a first book.
Me too. I also use and recommend the Fortran 95 Handbook by Adams, Brainerd, Martin, Smith and Wagener, but when I hit real trouble there is no substitute for c.l.f and the f95 or f2003 standard. Two or three times contributors to c.l.f have corrected views that I had formed after reading a misleading part of M&R or the Handbook. (In each case I told the authors, and they included the matter among things to fix in the next edition.) I still use M&R and the Handbook because they are almost always right, and much easier to read than the standards. And several c.l.f contributors do a great job of explaining obscure parts of the standards. -- John Harper, School of Mathematics, Statistics and Computer Science, Victoria University, PO Box 600, Wellington, New Zealand
|
Tue, 28 Oct 2008 09:52:14 GMT |
|
 |
Hani Andreas Ibrahi #6 / 6
|
 array element (matrix) question
Richard E Maine schrieb: Quote:
>> It works! I am looking for some useful books of fortran programming. >> Would you please recommend some books for me? Thank you very much. > I'm personally fond of Metcalf&Reid, particularly as a first book. It is > relatively short and concise, which helps get you going, and I think it > has a clear writing style. There are arguments for supplementing it with > something more comprehensive, but I think it is at least one of the > books that should be on a Fortran programmer's shelf.
I recommend "FORTRAN 90/95 for Scientists and Engineers", Stephen J. Chapman, McGraw Hill Higher Education (August 2003). IMO it is well structured and suitable for learning and reference. But FORTRAN 90/95 for Scientists and Engineers" is a textbook primarily. Chapman offers complete little sample programs and procedures and not only code snippets. IMHO this issue is very important for beginners because you can see the mentioned statements in a code context. The sample programs are very practical for people mentioned in the title and easy to understand. You will even find tricks and hints for your programming practice. Additionally you will find text boxes for good programming practice, Fortran 95-only statements and a abstract with training exercises after each chapter. The appendix contains the solutions and other useful tables. I also own "Fortran 95/2003 explained" from Metcalf&Reid. This book describe the language briefly. IMO it is a good reference and less suitable for learning. Here you will find the Fortran 2003 extensions also. Best regards, Hani
|
Tue, 28 Oct 2008 22:00:56 GMT |
|
|
|