next up previous
Next: About this document ...

ESC 251 HW 31 Due: Nov. 20

(6 pt) A common operation that needs to be performed on vectors is the dot product or scalar product. This is defined as

\begin{displaymath}\mbox{dot}(x,y) = \sum_{i = 1}^n x_i\,y_i \end{displaymath}

where x and y are two vectors of length n.

Write a function that will compute the dot product of two vectors and a main program to test your function. Use the vectors in the datafile to test your function.

Note that there is already an intrinsic F90 function that does this. Don't use the intrinsic function for this assignment.

(10 pts) Subroutines and functions can (and often do) call other subroutines and functions. Whenever you need to write a new function, it's a good idea to make use of any existing functions you have already written. Consider the binomial coefficient C(n,k) defined by:

\begin{displaymath}C(n,k) = \matrix{c} n \\ k \endmatrix =
n \ge k.\end{displaymath}

This quantity is comprised of three factorial operations. If you have a function available to compute n!, you can use this routine to compute n!, k! and (n-k)!. You can then combine these calculations to produce C(n,k).

Write a function that will compute the binomial coefficient given the values of n and k. Your function should compute the factorials in the binomial coefficient formula by calling the factorial function we wrote in the previous class. The template for your function should be

       FUNCTION getbinomial(n,k)
Use your function to compute the values of C(3,1), C(5,3), C(14,5), and C(10,0).

next up previous
Next: About this document ...