CS 100J Honours Autumn 2005 h/w 5 ... due by live demo (sign-up sheet in class)

Wednesday 30th November -- Friday 2nd December  

  1. First, to get a feel for what's going on, persuade MATLAB to draw the graph of
    y = cos(x)                      (use plot to do this).
    Then get it to draw
    y = cos(p*x)
    for a few different positive integer values of p. Repeat this for
    y = q*cos(p*x),
    where q = various real numbers between -2 and 2. Now you're warmed up, the first part of the exercise is to create a .m file called "prob2cos.m" that gets MATLAB to draw the graphs of y = S(n, x) for different values of n, where
    S(n, x) = cos(x) + (1/3)cos(3x) + (1/5)cos(5x) + ... + (1/n)cos(nx).
    It should make graphs for each n = 1,3,5,7,.. 21 (thus drawing 11 pictures -- notice that this example uses only odd numbers). MATLAB should pause between drawing each graph. You can write a function called S(n, x) if you like, but it is not needed to do this problem. It's the succession of (cumulative) graphs that we want to see. (Watch out for the slightly different syntax used in MATLAB for "for loops" compared with Java). Next, do the same thing for a different y = S(n, x), where
    S(n, x) = sin(x) + (1/2)sin(2x) + (1/3)sin(3x) + ... + (1/n)sin(nx).
    Your .m file should be called "prob2sin.m" and should make graphs for each n = 1,2,3... 21, pausing between each graph (thus drawing 21 pictures, since it uses both odd and even numbers).


  2. We now refine what we did above in question 2. You will hand in a MATLAB source file called "fourierApprox.m" that defines a function called fourierApprox. What this function will do is take in the name of a function as an input parameter (given in single quotes), and draw successive partial sum approximations (ie, various S(n,x) functions for increasing values of n) to that function. There are three .m files available on the course webpage that provide functions you can use to help do this problem. These are a.m, b.m, and proj.m. (If you're having difficulty downloading these files, then you might prefer to grab this text file instead.) The files a.m and b.m define functions that you can use to get the coefficients you will need below. (After downloading the files, type "help a" and "help b" from the MATLAB prompt to get help with these functions. If you're curious about the math, take a look at these files to see what they do!). The file proj.m is used by the files a.m and b.m. In what follows, (a1) and (b1), (a2) and (b2), etc., are constants whose values your program will find by calling the functions 'a' and 'b' provided on the website, and again we let the range of x be given by -10 <= x <= 10. Your function fourierApprox(funcname) should draw the graphs of y = S(n,x,funcname) for each n = 1,2,..21, where
    S(n, x, funcname) = (1/2)(a0) + (a1)cos(x) + (b1)sin(x) + (a2)cos(2x) + (b2)sin(2x) + .. + (an)cos(nx) + (bn)sin(nx)
    where (ak) = a(k, funcname), (bk) = b(k, funcname) for k = 1..n. Once you have written fourierApprox (and saved it in your MATLAB working directory), try it out on some actual functions! For example, if you type fourierApprox('abs') from the MATLAB prompt, it will show you approximations to y=abs(x) (the approximations will be accurate for -pi <= x <= pi, though not for larger or smaller x). Similarly, try fourierApprox('exp'), which will approximate e^x. Save the resulting figures (for n = 21) as encapsulated postscript files. Finally, write a function of your own called "myfunc", which is of the form y = myfunc(x) and saved in a file called myfunc.m. It can be whatever you like, but must work when x is a vector, and return some y that has the same dimensions as x. Then call fourierApprox('myfunc'), and save the final plot (with a title saying what function you used) as an encapsulated postscript file. Also save a plot of the actual function (i.e. plot(x, myfunc(x)) ) as an encapsulated postscript file. Submit fourierApprox.m, myfunc.m, and the specified postscript files as your problem solution. And you're done!

  3. Revisit the banking/commerce question from h/w 2. Aim to improve the separation and modularity of classes, have interfaces and appropriate abstract classes, think about security and authentication schemes (for example, possibly incorporate the secret sharing scheme discussed in class, consider some mild encryption of data, make your password/login system use a one-way function so that access to the encrypted passwords doesn't allow access to the person's data), ensure that classes and entities are as private as you can make them (so that things are kept as non-visible as possible), think about ways of avoiding information leakage, and try to ensure that transactions are performed in such a way that money is neither lost nor created and that if a transaction fails for some reason, data intergrity is maintained (think in terms of the 'atomic' principle discussed in class and consider ways of having some form of being able to roll back the data in case of a transaction failure). You should provide an intuitive GUI for interfacing with your system, and consider possible graphical ways of displaying the varying financial and other resources (for example, perhaps some graphs to show individuals/shops/banks/etc total resources over time, or fluctuating 'temperature' bars to represent current states. Feel free to utilise such data structures as you like, playing with sorting/searching amongst the other techniques you've learnt. Primarily, have fun and showcase your work. (There's a joint show-and-tell opportunity in Duffield Hall on March 8th 2006 called BOOM during which some of the more interesting solutions could well be demoed!!) You will find the material on threads helpful, and you will be able to implement a decent GUI for interacting with the program as part of this future assignment.