You are on page 1of 2

COT 3502

Computer Model Formulation

Spring 2013

Homework # 2
Due by 5 pm on Tuesday, January 29
In this homework you are asked to write VB subroutines and functions. In addition
to writing these functions, you should write a main program which would call these
functions and test your program using your own examples. Your Excel files should
contain the test programs and the test examples (stored in the spreadsheet) in addition
to your functions/subroutines.
Follow the same submission guidelines as for the previous homework.

Problems
1. (10 points) In class we have developed subroutines for input/output of square matrices.
It will also be convenient to have subroutines for input/output of vectors (i.e. 1d
arrays). Modify the subroutines written in class and write subroutines read_vector
and write_vector for reading/writing vectors to/from a spreadsheet. The format for
calling these subroutines should be as follows:
Call read_vector(x, N, R, C)
Call write_vector(x, N, R, C)
Here, x is the vector to be read/written, N is the length of the vector x, and R and
C are the numbers of the row and column containing the first element of the vector.
Assume that the vectors are stored as columns in a spreadsheet.
You may need to use the developed functions in the following problems.
2. (10 points) Write function sum_vector which computes the sum of all components of
a given vector. The format for calling this function should be
S = sum_vector(x,N),
where x is a given vector, N is the length of this vector, and
S=

N
X

xi .

(1)

i=1

3. (15 points) Write subroutine mat_vec_product to compute a product of an N N


matrix and an N -dimensional vector. The format for calling this subroutine should be
Call mat_vec_product(A,x,Ax,N),
1

COT 3502

Computer Model Formulation

Spring 2013

where A is an N N matrix, x is an N -dimensional vector, Ax is the product of A and


x, and N specifies the sizes of A and x.
4. (15 points) Write subroutine mat_product to compute a product of two N N matrices.
The format for calling this subroutine should be
Call mat_product(A,B,AB,N),
where A and B are N N matrices, AB is the product of A and B, and N specifies the
sizes of A and B.

You might also like