Physics 222 Assignment 6

Due March 16

Directions

Only do this assignment if you are not doing a project.

Please turn in this assignment by emailing them to me . Please use the subject of "Physics 222 HW6" for this assignment (if you use the link above, the subject will be added automatically). Please attach the source code to any programs that you write for this assignment. If you write more than one program, attach each separately. When answering the questions themselves feel free to answer directly in the body of your message (or attach your answers).

  1. Matrices and vectors

    In this program you will get some practice using some of Fortran's arrays features.

    Your program should declare two allocatable, 2D, real arrays A and B. The arrays will be square arrays of equal sizes. Your program should prompt for the sizes of the arrays and then initialize them so that the value of aij = (-2 i)j and bij = 4*i * j, where i is the row number and j is the column number.

    Your program will then do several calculations with these arrays and print the results of each to the screen.

    1. For each array it will take the square root of the sum of each array element multiplied by itself.
    2. It will calculate the matrix multiplication C= A B of the two arrays.
    3. It will find the dot product of a given column vector of A with a given row vector of B. Your program should prompt for which row and column to use.
    4. Finally, your program will find a array D. Where aij < bij, dij = π aij2, otherwise dij = aij* bij.
    You should run this program for the following sets of input:
    1. 2 x 2 arrays, dotting and crossing the column 1 and row 2, respectively.
    2. 3 x 3 arrays, dotting and crossing the column 2 and row 2, respectively.
    3. 5 x 5 arrays, dotting and crossing the column 5 and row 1, respectively.
    4. 8 x 8 arrays, dotting and crossing the column 4 and row 2, respectively.
  2. Leaky Water Tower

    Consider the case of a cylindrical water tower with a leak on its side near the bottom of the water tank. If we know the area of the hole, then the change in volume is:

     dV/dt = - v A
    where the velocity that the water leaves the hole can be determined from fluid mechanics. Convert this problem to a difference equation and solve it numerically for the height of the water as a function of time. Your program should read the numerical parameters from a file. The input file will contain (in order) the size time step to use in seconds, the initial height of the water in meters, the radius of the water tower in meters, and the area of the hole in cm2. Also assume that the tank is open on the top. Find the total time it takes water to drain from the hole, and plot the height of the water as a function of time for your results. Run your program for the files water_tower1.dat and water_tower2.dat.