<< Return to class page

Math 151 Lab 02 - 01/22/2017:

DUE: Wednesday, January 24, 2017 (by 4:00pm before class starts)

Contents

INSTRUCTIONS:

Save this Matlab script with the filename LastName_Lab02.m (example: Lewis_Lab02.m). Complete each question (either in words or with Matlab code). When you are ready to have your assignment graded, choose the PUBLISH command from the file menu, and submit the resulting file to CANVAS.

Please make sure to leave code uncommented unless I ask for a comment. You do not need to label your steps for each problem, but I should be able to see you do each step I asked for.

Place your work below the dashed lines.

#1

WRITE CODE BELOW:

Step 1: Create a vector x of length 10.

Step 2: Set the value of x at each index to be equal to the index value using a loop. (i.e. write a loop so x(1)=1, x(2)=2, ...)

------------------------------------------------------------------------

#2

WRITE CODE BELOW:

Step 1: Create a vector x of the numbers 1 through 100.

Step 2: Find the sum of all numbers from 1 to 100.

Step 3: Compute 100*(100+1)/2

Note: This formula works for any integer in the place of 100.

------------------------------------------------------------------------

#3

WRITE CODE BELOW:

Step 1: Set x=[3,9,5,10,1,0,7,9] and c=0.

Step 2: Use a for loop that iterates over x and, if an entry of x is strictly larger than 5, adds 1 to the counter c. Then print the counter to the screen.

------------------------------------------------------------------------

#4

WRITE CODE BELOW:

Step 1: Set x to the vector [1/1, 1/2, 1/3, 1/4, 1/5, ..., 1/50] using a for loop.

Step 2: Compute the sum of these numbers.

Step 3: Repeat steps 1 and 2 but use x as [1/1, 1/2, 1/3, ..., 1/100] and also [1/1, 1/2, 1/3, ..., 1/1000].

WRITE COMMENT BELOW:

Do each of those sums look like they're closing in on a specific value? If so, please guess a value (this will be graded loosely).

------------------------------------------------------------------------

#5

The fibonacci sequence is the sequence 1, 1, 2, 3, 5, 8, 13, 21, ... where you can find the next value by 2 = 1 + 1, 3 = 2 + 1, 5 = 3 + 2,...

WRITE CODE BELOW:

Step 1: Initialize a vector x so that it has length 100 and x(1) and x(2) are 1.

Step 2: Use a for loop to fill in the remaining entries in x so that it matches the fibonacci sequence.

Step 3: Create a new vector called y of length 99 and fill it so that it looks like [x(2)/x(1), x(3)/x(2), x(4)/x(3), ..., x(100)/x(99)].

WRITE COMMENT BELOW:

As you read through the values of y, they should be closing in on a specific value. What is this value?

------------------------------------------------------------------------