[CMSC 455] | [Syllabus] | [Lecture Notes] | [Homework] | [Projects] | [Files] | [Notes, all]
Homework must be submitted when due. You loose 10%, one grade, the first day homework is late. Then 10% each week thereafter. Max 50% off. A zero really hurts your average! Homework is always due on a scheduled class day before midnight. If class is canceled then homework is due the next time the class meets.
Get any of my files you need on linux.gl.umbc.edu cp /afs/umbc.edu/users/s/q/squire/pub/download/some_file.c . Be careful saving a file from a web page. You may have to fix broken lines.
The "submit" facility only works on the "gl" machines. The student commands are: submit cs455 hw1 some_file submit cs455 hw1 some_file another_file output_file submitrm cs455 hw1 submitls cs455 hw1
Modeling and simulation: Rocket flight, how high? In a language of your choice, write the program defined in lecture 2. Test your program and produce an output file, then submit both files on a GL machine: submit cs455 hw1 your-source your-output
In a language of your choice, write a program that does a least square fit of the thrust data used in Homework 1. Use your data x = 0.0 0.1 0.2 ... 1.9 y = 0.0 6.0 14.1 ... 0.0 Be sure time 0.0 has value 0.0, time 1.9 has value 0.0 Do the least square fit with 3, 4, ... , 17 degree polynomials. Compute the maximum error, the average error and RMS error for each fit. If convenient, look at the plots of your fit and compare to the input. Print out your data. Remove excess printout, print: Print out your polynomial coefficients for each degree 3..17 Print out maximum, average and RMS error for each. Lecture 1 shows how to compute error copy whatever you need from Lecture 4, Least square fit Submit your source code file(s) and your output file submit cs455 hw2 your-source your-output My MatLab errors looked like:hw2_m.out (with a lot of complaints from MatLab!) My "C" errors did not improve as much:hw2_c.out Plotting three points between each starting point in MatLab, n=19, gave:The steps are typically: Have the thrust data in X array, time values. Have the thrust data in Y array, newton values. Build the least square simultaneous equations, n=3 first Given a value of Y for each value of X, Y_approximate = C0 + C1 * X + C2 * X^2 + C3 * X^3 Then the linear equations would be: | SUM(1 *1) SUM(1 *X) SUM(1 *X^2) SUM(1 *X^3) | | C0 | | SUM(1 *Y) | | SUM(X *1) SUM(X *X) SUM(X *X^2) SUM(X *X^3) | | C1 | | SUM(X *Y) | | SUM(X^2*1) SUM(X^2*X) SUM(X^2*X^2) SUM(X^2*X^3) |x| C2 | = | SUM(X^2*Y) | | SUM(X^3*1) SUM(X^3*X) SUM(X^3*X^2) SUM(X^3*X^3) | | C3 | | SUM(X^3*Y) | Note that index [i][j] of the matric has SUM(X^(i+j)) Solve the simultaneous equations for C0, C1, C2, C3 using some version of "simeq". Compute errors by using "peval" with the coefficients for each X and subtract the corresponding Y. Save maximum error, compute average and RMS error. Print. Repeat, advancing n to 4, 5, ..., 17 If you use least_square_fit.c or least_square_fit.java make changes in function data_set put in time and thrust data from homework 1 k=20 xx=time[i] in java, i is idata yy=thrust[i] in java, i is idata
See Lecture 9
1. Compare two methods of integrating sin(x) from 0 to 1 Take as the exact solution -cos(1.0)+cos(0.0) = 1.0-cos(1.0) Print out number of points, your integration computed value, and your_computed_value - exact_solution the error 1.a) Use the trapezoidal method with 16, 32, 64 and 128 points. Put this in a loop e.g. in C for(n=16; n<=128; n=n*2) Note how the error decreases as n increases. h = 1/n your_value = h * ((sin(0)+sin(1.0))/2 + sum i=1..n-1 sin(i*h)) 1.b) Use the Gauss Legendre method with 8 and 16 points. Copy the function gaulegf from your choice of language or convert to your choice of language. Be sure to keep the #undef abs and #define abs in "C" code. double x[17], w[17] n=8 then again for n=16 gaulegf(0.0, 1.0, x, w, n) your_value = 0.0 for(j=1; j<=n; j++) your_value = your_value + w[j]*sin(x[j]) Note the significantly smaller error than for trapezoid. 2. Write a small program in the language of your choice to numerically compute, to at least 3 significant digits, the area that is outside Circle 1 and inside both Circle 2 and Circle 3,e.g. inside if x^2+y^2<9, outside if x^2+Y^2>9 Circle 1 center at (2,2) radius 1 (x-2)^2+(y-2)^2=1^2 Circle 2 center at (0,2) radius 2 x^2+(y-2)^2=2^2 Circle 3 center at (0,0) radius 3 x^2+y^2=3^2 Method: count the dots in the area and multiply count by the area of a square. Run with a grid 0.1, 0.01, 0.001, 0.0001 to see if your computation is converging. Obviously, if the left hand side of the equation is larger than the right hand side of the equation, the point is outside the circle.submit cs455 hw3 your-source your-output for 1a, 1b and 2 (Note: in problem 2, if you were given a function z=F(x,y) and needed to compute the volume over the area, you would probably combine part of problem 1 with problem 2.)
Use a language and big numbers package of your choice to compute the exact integer value of the following: How many ways can you lay out a deck of cards in a line? 52 cards in a deck, all permutations is 52!. Thus, just compute 52 factorial. How many five card hands from a deck of 52 cards? This is an n choose m problem. n! / ((n-m)! m!). n is 52, m is 5. Direct computation, no math reductions. print all digits as an integer, big number, no scientific notation E+xx. Submit your source code and your output. (Clean out unused source code, it should be small.) ((Typically have a fct(n) function in your code.))
See Lecture 19
Take a .wav file. Listen to it. Extract the amplitude data from the .wav file. Use a FFT to get the frequency spectrum. Modify the frequency spectrum Use inverse FFT to get amplitude data. Insert the modified amplitude data into the .wav file. Listen to the new .wav file. Just do one of, a) b) c) a) delete high and low frequencies from the spectrum or perform some other modification. Comment on how the sound changed. b) Move all of the spectrum from i to n down into 1 to n-i, zero spectrum from n to top. You should be able to understand the modified .wav yet it will be a much deeper voice. You have lowered the frequency. c) Mess up the sound with some other change to the spectrum. Look at the spectrum plots. It depends on what code you use: Possibly leave the zeroth frequency alone or zero it. For N=2^n, leave the N/2 as it is, this is the Nyquist frequency. Moving the top half down and the bottom half up, raises the pitch. It also introduces noise. Sample code for FFT and IFFT provided. copy whatever you need from Lecture 18, FFT Sample code to read and write a .wav is provided for a few languages. waveplay.m reads a .wav file, plays the file at three speeds, then writes a .dat file with just the sound. The .dat file can be read with %f format. soundplay.m Will play a .dat file, that may be read, modified, and rewritten. In Matlab, if it works for you, use fft_wav.m In Python, hack sound.py and use Python's fft and ifft. In Java, hack ClipPlayerTest.java and use my Cxfft.java for fft and ifft functions. There is read_wav.java to read and write .wav files. Or, if it works for you, use fft_wav.java With a plot, use fft_frame.java In Ubuntu using plain "C", hack pcm_dat.c and use any of the FFT and IFFT written in "C". The program read_wav.c reads and writes a .wav file. You can put a FFT in between the read and write for your homework. Use common existing software to play the .wav file(s). You may need to convert complex values to magnitude. Given a+bi amplitude = sqrt(a*a+b*b) Submit your source code, input .wav files and output .wav files. (option: use just ascii files of numbers, read and write with %f MatLab code soundplay.m plays file. short_count.dat is one two three.) See Lecture 18 for more information
Compile and run the program time_matmul.c on some computer. You may use other languages and MatLab. Time the matrix multiply for 100 by 100, 200 by 200, 400 by 400 etc and record the actual time and a normalized time. It is OK to stop when a single size takes over 10 minutes. The normalized time is some constant time actual time divided by N^3. Matrix multiply is order N cubed, thus the time goes up by a factor of 8 each time N doubles. Note that the small 100 by 100 runs very fast. As the matrix gets larger, the time increases by more than a factor of 8. This is because of cache performance verses memory bandwidth. If you can not run "C", a Java version, much slower, is: time_matmul.java If you want a really slow version, run the Python: time_matmul.py Actually, you should be using numpy for numerical computation. Comment on any large variation in normalized time on the language and operating system and machine you run this homework. Submit your code (or my code) and your output.
See Lecture 29
Last updated 10/15/2014