CS368 Homework 1
Lec 1, Spring 2016
Due by 11:59 pm on Monday, February 8 (not accepted late)

Announcements

Check here periodically.

1/31/2016  Homework assigned. To ask questions about the homework and see questions posed by other students and their answers, go to: http://www.piazza.com/wisc/spring2016/cs368 and sign-in using your wisc.edu account.

Problems

To get started, download this MATLAB script:

homework1.m

Save the script (e.g., in a MATLAB/homework1 folder - if you don't have a homework1 folder, you can create one when you save the file).

Launch MATLAB and open the homework1.m script. The file is a text-only file that opens in the Editor window in MATLAB. Edit your homework1.m file with your name and answers to the problems.

Part 1: (5 points) Learn@UW Survey

Log on to Learn@UW and take the 5-question survey. You can get to the survey by selecting "Quizzes" from the "Assignments" pull-down menu in the red banner at the top of the main 368 page.

Part 2: (14 points) Writing MATLAB commands

Question 1 (7 points)

Write exactly one assignment statement to create each of the following vectors or matrices. Assume that any variables appearing on the left side of an assignment statement do not exist prior to the assignment statement being executed.

To receive full credit, you may only make use of the built-in MATLAB functions ones, zeros, eye, and diag as well as MATLAB operators (such as *, +, :, or ' ). You may not give the vector or matrix explicitly (or use loops). For example, to create

xx =  1  2  3  4  5  6

The code xx = 1 : 6 is acceptable; the code xx = [1, 2, 3, 4, 5, 6] is not.

  1. q1a =  4   4   4   4   4   4   4   4   4
    
  2. q1b =  0   0   0  
           0   0   9
    
  3. q1c =  1  4  9  16  25  36  49  64
    
  4. q1d =  2  6  10  14  18  20  15  10  5  0
    
  5. q1e =  1  0  0  0  0
           0  3  0  0  0
           0  0  5  0  0
           0  0  0  7  0
           0  0  0  0  9
    
  6. q1f =  0  0  0  2  2  2 
           0  0  0  2  2  2
           0  0  0  2  2  2
           1  1  1  3  0  0
           1  1  1  0  3  0
           1  1  1  0  0  3
    

Question 2 (7 points)

Suppose the variable data, info, and vec have been defined as follows:

data = [ 2 7 4 3; 3 4 7 6; 8 3 5 1; 1 4 2 6; 7 2 2 5 ];
info = [ 1 2 3 4; 3 2 4 1; 2 4 1 3; 4 3 1 2 ];
vec = [ 4 1 9 5 6 3 2 7 8 ];

Use MATLAB's matrix element access syntax to complete each of the following actions using only one assignment statement. To receive full credit, you may only use MATLAB's matrix element access, the : operator, and the transpose (') operator.

  1. assign the transpose of the second row of data to q2a

  2. assign the first 3 columns of data to q2b

  3. assign the second and fourth values of the first and third row of info to q2c

  4. create the matrix q2d whose first row contains the first two rows of data and whose second row contains the last two rows of info, i.e., q2d should contain
    2  7  4  3  3  4  7  6
    2  4  1  3  4  3  1  2
    
  5. change vec so that the values at even-numbered indices are 0, i.e., so that vec becomes 4 0 9 0 6 0 2 0 8)

  6. change info so that its second column contains the values of the third row of data, i.e., so that info becomes
    1  8  3  4 
    3  3  4  1 
    2  5  1  3 
    4  1  1  2
    
  7. change data so that its first and fourth columns have been switched

Style and Technique (1 point)

Part of your score on this (and, really, every) assignment is based on your style and technique. Included in this are the following:

  • File and variable names must be exactly as specified (including capitalization).
  • Your script must include output that demonstrates that your commands are doing the correct thing. This means you should always display the results of your commands (by either using the disp() command or by not suppressing the output). (Two exceptions, which don't come into play for this particular assignment: (1) you may suppress the output of commands that create result vectors that are then plotted; (2) commands inside the body of a function should have their output suppressed.)
  • Variables names that you create must be descriptive and follow naming conventions.
  • Variables must be used to access previously computed results; you should never retype a computed value.

Handing in

In order for your work to be considered to have been turned in on-time, you must complete the survey and upload your file to your Learn@UW Dropbox by 11:59 pm Monday, February 8.

Last Updated: 1/31/2016     © 2016 Beck Hasti, hasti@cs.wisc.edu