Homework #0 Clarifications & Reference Solution:

Malformed expressions (i.e. input that doesn't match one of the given cases): Don't worry about it. Your program may behave well, badly, or die a horrible horrible flaming death. We don't care.

Format of input: All arguments should be space-separated - be sure not to run them together, or much pain will result. The handout has some of the arguments run together (e.g. c = a.b) - this will break the parser; instead write "c = a . b"; similarly for the other commands.

Printing of vectors/matrices that haven't been assigned yet: don't worry about initializing everything ahead of time; we won't be trying to print anything that hasn't been assigned.

Automatically printing after assignment: doesn't really matter one way or another. Once you've done the assignment, you can print out the results if you'd like, or not. Your call; we don't care.

Printing matrices: To make your life easier, I'd suggest tossing a \n after every three %f's, to print your matrix out in matrix form, rather than all on one line. This isn't required; it just makes it easier for you to read it.

Compiling: If you haven't compiled a C program before, write your program in one .c file (such as matvec.c), then at the command line (while in the directory where your code is) type 

   gcc matvec.c -o matvec

(with matvec replaced by whatever your filename is).

Reference solution:

Following is a sample run courtesy of Brennan Sellner: (you don't need to add the "?" prompt or the little informational messages; I just felt like it. :-). You only need to make sure that your vectors and matrices have the correct values; don't worry about formatting, etc.:

For testing, you can save yourself a lot of typing by putting all your input into a text file and running: 

   cat matvec_test.txt | matvec

Where "matvec_test.txt" is that input file you just made. You can find the input file here or in the same dir as matvec

? a = 1 2 3
Assigning to vector
? a
1.000000 2.000000 3.000000
? b = 1 1 1
Assigning to vector
? b
1.000000 1.000000 1.000000
? c = a + b
Adding vectors
? c
2.000000 3.000000 4.000000
? c = a . b
Dotting vectors
? c
6.000000 0.000000 0.000000
? c = a * b
Crossing vectors (beware the Stay-Puft Marshmallow Man!)
? c
-1.000000 2.000000 -1.000000
? A = 1 1 1 1 1 1 1 1 1
Assigning to matrix
? A
1.000000 1.000000 1.000000
1.000000 1.000000 1.000000
1.000000 1.000000 1.000000
? B = 0 0 1 0 1 0 1 0 0
Assigning to matrix
? B
0.000000 0.000000 1.000000
0.000000 1.000000 0.000000
1.000000 0.000000 0.000000
? C = A + B
Adding matrices
? C
1.000000 1.000000 2.000000
1.000000 2.000000 1.000000
2.000000 1.000000 1.000000
? D = C * B
Multiplying matrices
? D
2.000000 1.000000 1.000000
1.000000 2.000000 1.000000
1.000000 1.000000 2.000000
? a
1.000000 2.000000 3.000000
? f = D * a
Doing Matrix-Vector multiplication
? f
7.000000 8.000000 9.000000
? END