0% found this document useful (0 votes)
27 views2 pages

Homework # 2

This homework assignment asks students to write VB subroutines and functions to perform operations on vectors and matrices. It provides 4 problems to solve: 1) Write subroutines to read and write vectors to a spreadsheet. 2) Write a function to calculate the sum of a vector. 3) Write a subroutine to calculate the product of a matrix and vector. 4) Write a subroutine to calculate the product of two matrices. Students are instructed to test their code using sample data and examples stored in an Excel file.

Uploaded by

0Kira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

Homework # 2

This homework assignment asks students to write VB subroutines and functions to perform operations on vectors and matrices. It provides 4 problems to solve: 1) Write subroutines to read and write vectors to a spreadsheet. 2) Write a function to calculate the sum of a vector. 3) Write a subroutine to calculate the product of a matrix and vector. 4) Write a subroutine to calculate the product of two matrices. Students are instructed to test their code using sample data and examples stored in an Excel file.

Uploaded by

0Kira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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