DOC PREVIEW
UTSA CS 1173 - Program Control Worksheet

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 1173: MATLAB Program Control Worksheet 1. Trace each of the following loops. Show all of the values that the variables take on in the boxes at the right. Also show any output if any. k x a) A simple loop for k = 1:3 x = k*k; fprintf('x =%g\n', x); end; b) An accumulation using a loop k x x = 5; for k = 1:3 x = x + k*k; end; fprintf('x =%g\n', x); c) An array using a loop k x x = [1, 2, 3, 4]; for k = 1:4 x(k) = 3*k; end; c) An array update equation k x x = [1, 2, 3, 4]; for k = 2:4 x(k) = x(k-1) + 3*k; end;2. Trace each of the following if statements. Show all of the values that the variables take on in the boxes at the right. Also show any output if any. x y y = 2; x = 35; if x <= 40 y = x + 3; else y = y + 10; end; 3. Translate the following into MATLAB code. Assume x, y, z, and h contain a single value. Assume measles is a vector containing the number of cases in each year from 1921 to 1950. a) If x is less than or equal to z, set y to 3. Otherwise, set y to 4. b) If h = 1, output a message that the null hypothesis is rejected. c) If the average number of measles cases is greater than 10, print a message. d) Define total21 to be a MATLAB variable containing the total number of measles cases for the years 1921 to 1930. If total21 is between 400 and 1000 inclusive, set the variable bigDecade to true. Otherwise set the variable bigDecade to


View Full Document

UTSA CS 1173 - Program Control Worksheet

Documents in this Course
Load more
Download Program Control Worksheet
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Program Control Worksheet and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Program Control Worksheet 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?