See the grading guidelines for information about grading policies and turn-in procedures.
NOTE: there are two types of homeworks - assignments, which will be frequent and not graded but discussed in class, and projects, which will (mostly or entirely) be done as group work and will be graded. Projects will be clearly identified below, and will be described in individual project pages linked to this one.
Whether assignments or projects, late homeworks will not be accepted.
What operating system runs on the laptop computer you will use for coursework in CAAM 420? What is its relation to Unix?
One page (or less) should be sufficient; don't worry too much about formatting, but make sure it's readable. Name the file "hw1.txt" and Upload to your repository by the due date.
Structure your file as follows:
The hw_2 directory should contain both the source, as hw1.tex, and the pdflatex output, as hw1.pdf.
submit a directory named hw_3 under your main repo directory, with your solution of the problem as its contents (hw_3/hw3.c).
The 2-vector function (cos t, sin t) obeys the system of differential equations
d/dt (cos t) = -sin t,
d/dt (sin t) = cos t
with initial conditions cos 0 = 1, sin 0 = 0.
Euler's method to approximate the solution of this system on the interval [0,pi] goes like this: choose a positive integer N, and divide the interval [0, pi] into subintervals of length pi/N, with N+1 endpoints t0, t1, ... tn: the ith endpoint is ti = i(pi/N). Compute approximate values (c[i], s[i]) for cos ti, sin ti, i=0,...,N, by following this rule:
c[0]=1, s[0]=0
for i = 1,...N,
c[i] = c[i-1] - s[i-1](pi/N)
s[i] = s[i-1] + c[i-1](pi/N)
Write a program implementing Euler's method. Store (c[i], s[i], i=0,...N) in C arrays of length N+1. Write a "for" loop to implement the recursive rule above. Print the value of c[i] for each i.
Choosing N: Note that cos pi = -1. Try N=2, N=3, ..., until you find an N for which c[N] is a 1-digit approximation to -1, i.e. c[N] is between -1.1 and -0.9.
Submit your work in a directory hw_4 under your repository root, containing your code as hw4.c. The submitted version should have N set to a value satisfying the 1-digit criterion stated in the last paragraph. If you use cstd.h, include it in your hw_4 directory.
The IEEE standard decrees that floats should consist of 32 bits, as follows:
Having worked this out, write a program which prints
double dpi = 4.0*atan(1.0);
Then assign dpi to a float fpi, and print them both with 15 significant digits (conversion %20.15e in printf). At which digit do they start to differ? This tells you roughly how many digits a float represents.
Condition: You may consult with the instructor and TAs, who may provide relevant advice, but will not directly assist you in doing the assignment. You may not discuss the assignment with your fellow students prior to turnin.
Lab: TAs will be available in Sewall 305 on Friday 27 Sep during the usual class hour to provide advice.
Objective: write a program printing the binary representation of a float, in the following format:
SIGN=... MANTISSA=... EXPSIGN=... EXPONENT=...
The sign (SIGN) and exponent sign (EXPSIGN) should be printed as 0 or 1, meaning positive or negative. The mantissa should be printed as a string of 23 characters, each either '0' or '1'. The most significan bit, i.e. the coefficient of the highest power of 2, should come first (this may not be the way the bits are stored in the machine, but it is the natural way they would be presented in text). The exponent should be printed as a string of seven characters, each either 0 or 1.
Your program file should be called float2bin.c. It should generate a command (say a.out) which is called as follows:
./a.out [real number in floating point notation]
and print the binary representation in the format described above.
Hints:
float x;
...
unsigned int * u = (unsigned int *)&x;
An unsigned int is just a pile of bits, so now *u has your 0's and 1's.
Turnin: Submit a directory hw_5 to your repository, containing float2bin.c, and any other files (for example cstd.h, if you use it) necessary to run the program. It should be possible to type "gcc float2bin.c" in your directory and obtain the command (as a.out) performing the task described above.
Grading: I will test your program by running it on several examples, to be revealed later.
Condition: This assignment is NOT pledged. You may work with other students, and consult the TAs and Instructor for advice. HOWEVER, all text, including code, in your turnin directory must be your own. If you've worked with others on this assignment, include the names of the group members in a README file in the turnin directory.
Lab: TAs will be available in Sewall 305 on Wed 9 Oct during the usual class hour to provide advice.
Objectives: Enhance the cvector package from the class examples to include file i/o, matrices, and matrix-vector multiplication. Provide files containing the necessary function definitions, and program files (containing appropriate "main" functions) to write, read and display vectors, matrices, and matrix-vector products. Build the project with make.
Specifically,
for example. Use the stdio file functions (fprintf, fscanf) to implement functions for reading and writing VECTOR data in this form, with these signatures:
int vec_fprint(VECTOR, char *);
int vec_fscan(VECTOR *, char *);
vec_fprint should write the contents of its VECTOR to the file named in the "char *" argument: i.e.
vec_fprint(v, "foo.vec");
should write v to foo.vec in the format described above. Conversely,
vec_fscan(&w, "foo.vec");
should read the contents of the file foo.vec into the VECTOR w.
Use the suffix ".vec" on all of your VECTOR files - that way, it's obvious which they are, without looking into them.
VERY IMPORTANT: "trap" all errors you can anticipate. In the event of an error condition occurring in one of your functions, print an informative error message and return from the function immediately - for vec_fprint and vec_fscan, the return value should be non-zero in the event of an error, zero for normal return. specifically, trap these errors:
float * vdata = ... (allocate nrows*ncols floats)
float ** data = ... (allocate nrows float *'s)
... data[i] = &(vdata[i*ncols]) ...
A question: you will need to allocate the float * vdata, in order to guarantee (this is worth it!) that the matrix data occupies a single contiguous block of memory. Will you need to keep vdata as one of the data members of the MATRIX struct?
Write a set of functions precisely analogous to the functions in cvector.c, stored in a file cmatrix.c. For the file storage, use a similar format to the VECTOR storage mode: nrows on first line, ncols on the second line, then the vector data, row by row, starting with the first row, one float per line (so your file will have 2 + nrows*ncols lines). Be very careful to trap all errors that you can anticipate.
Finally, add to cmatrix.c a definition of matrix multiplication, implemented in a function with signature
int matvec(MATRIX a, VECTOR x, VECTOR b);
Calling this function should store the product of a matrix (first arg) and vector (second arg) in another vector (third arg). Trap all errors - especially, check that the dimensions are compatible.