Week 12 Questions


Fortran

If you attempt something like MATMUL(A(2,1),B(2,1)) will it give you an error message, or do you need to build in diagnostics?

Yes, that is a Fortran syntax error. "matmul" wants arguments that are simply names of whole arrays. You have given it 2 elements of arrays as arguments.

What is the difference between DIM=1, and DIM=2?

If I define 3 arrays with "REAL A(3,5), SROW(5), SCOL(3) then the line

      SROW = SUM(A,DIM=1)
is the same as the following double loop, in which I sum the contributions of all rows within each column.

      DO 200 J=1,5
         SROW(J)=0
         DO 100 I=1,3
            SROW(J) = SROW(J) + A(I,J)
 100     CONTINUE
 200    CONTINUE
and for the other dimension

      SCOL = SUM(A,DIM=2)
is the same as summing the connects of all columns for each row, as done in the following double loop

      DO 200 I =1,3
         SCOL(I)=0
         DO 100 J=1,5
            SCOL(I) = SROW(I) + A(I,J)
 100      CONTINUE
 200    CONTINUE
When would you use LBOUND, UBOUND, SIZE, an SHAPE in a program?

The truth is that I would be very unlikely to use SIZE and SHAPE, due to my programming style (neolithic). However, LBOUND and UBOUND are very useful in establishing bounds for DO loops in subprograms that don't have clear variables passed defining the smallest and largest allowed array index. You will see structures that permit this lack of information, when we get into the talk about use of the INTERFACE structure on Monday. If you want to look ahead, take a look at interface.f for an example of use of SIZE. It is one of those rare intrinsic functions like SELECTED_INT_KIND that is appropriate for use in type statements. I haven't generated an example using SHAPE, but the array resulting from use of SHAPE, could be passed as an argument to a subprogram, and the elements in that argument used to establish the sizes of each dimension in one or more arrays used by the subprogram.

Will we need to know all of the intrinsic functions (UBOUND, LBOUND, SIZE, ...)? What kind of practical uses do they have?

Know that the capabilities exist, but don't bother memorizing the names. This will let you search your favorite Fortran manual (or class notes) for details on the Function when you need it. Know how to apply the DIM argument. Know that Fortran 90 functions can do Matrix multiplies, and Dot Products, and although we didn't get to it in class, know that they can do the transpose of a matrix.

See above for practical uses of LBOUND and UBOUND. I use MATMUL, DOT_PRODUCT, and TRANSPOSE operations as a part of more complicated procedures for the efficient solution of very large systems of linear equations, particularly ones that have special "Sparse" (lots of zeros) structure.

What is the rank of an array, again?

The rank of a Fortran array is just the number of dimensions (subscripts) that it has. For the type statement "REAL A(10), B(5,3), C(3,3,4), D(6,6,6,6)", A has rank 1, B has a rank of 2, C has a rank of 3, and D a rank of 4.

General Computing

How do you know what all of the Programs do on Netlib? Would you teach us more about it?

Simple answer is that I don't know what they all do. There are so many, and many have very specialized methods that take a while to appreciate. You need to go to Netlib with an application in mind, then use the search function to see what you can find. Also, if you look in the section opened when you click on "browse", you will find a highlighted phrase that lets you get more description of items like "linpack", "minpack", "itpack". I'll try to do some more with Netlib when we start solving differential equations.

Class Procedures

What percent of the final will be on new material?

40-50%

Since Homework 11 is in two parts, what file or files do you want us to leave it in?

Part 1 in "hw11a.f", and Part 2 in "hw11b.f"

I'm a little confused about HW11. It seems like all we are doing is copying files. What programming are we doing?

In Part 1, you are modifying my program to test the 2 Linpack subroutines for any matrix size that you want to specify with the parameter statement. Mostly it just forces you to understand what I have done, but does involve changing a few of my lines, and adding a few of your own. Get used to this mode of operation. Reuse of other code for a related task is generally a big time saver.

In Part 2, you can program to your heart's content. Many students choose to modify my quadfit subroutine to form the core of the fitting process, but the main program, input, and output really need to be done from scratch.

What can we expect for Homework during the rest of the semester?

I will post a final Homework problem by Wednesday, to work the cannon problem one last time. It will be an exercise in the solution of Ordinary differential equations. You should start writing the basic framework of the program immediately, and not wait for full information on how to program the equation solution.

Computational Solution Methods

What do Least Squares do?

"Fits" a line or curve to a set of data points. By now you should know that with 2 points you can exactly determine the slope and intercept of a straight line passing through the points. What if you have 10 points, that should fall on a straight line, but because of experimental error, don't really line up. There is no single straight line (y = m x + b) that passes through all ten points. The best that you can hope for is a line passing near all 10 points, but probably not through any of them. The problem is to come of with a systematic method for defining "near" and finding the line that is nearest the points. That's where least squares comes in.