Program: Matrix-Vector Evaluator
Write a program that
runs under unix to perform 3x1 vector and 3x3 matrix arithmetic.
The program
should take from standard input one line at a time a sequence of
expressions, described below.
A line with nothing on it should do nothing. The
command END should terminate the program.
The following are the commands to be defined:
- Vector and Matrix instantiation.
For vectors, a lower case letter
followed by an ``='' sign, and then followed by three numbers sets the value
for the vector. For matrices, an upper case letter, followed by an ``=''
sign, and then followed by nine numbers sets the value for a matrix. To make
things easier, assume there could only be 26 vectors and 26 matrices. Hint:
there is a nice relationship between chars and ints in C.
- Printing.
A vector or matrix on a line by itself followed by return
should print the vector or matrix in their appropriate forms.
- Addition.
c = a + b ------ store the sum of a and b into c.
C = A + B ------ store the sum of A and B into C.
- Multiplication
c = a.b ----- should compute the dot product of a and
b and store in it in the first component of c. (Set the other components of c to zero)
c = a*b ----- store the
cross product of a and b in c
C = A*B ----- perform matrix
multiplication of A and B
v = M*x ----- perform the matrix-vector
multiplication.
Feel free to use this sample code written by
Cuban and commented by Howie (though you may do this your own way if you like).
Take a look at some clarifications, sample input and a sample program here.
[-Compiling in Clusters-]