Question

Extra Problem #1: By hand, determine all variable iterations of the nested for loop below: loop...

Extra Problem #1:

By hand, determine all variable iterations of the nested for loop below:

loop = [-4 7 5];

initial = 2:2:20;

value = 10:-1:1;

k = 1;

build = ones(3,6);

for m = 1:length(loop)

for n = 3:-1:1

stamp(n) = loop(n) + initial(m) -value(m+n)

end

build(:,k) = stamp'

k = k + 2

end

Homework Answers

Answer #1
all variable iterations of the nested for loop are stamp, build and k

Trace:
-----------
stamp =

   0   0   0

stamp =

   0   1   0

stamp =

  -11    1    0

build =

  -11    1    1    1    1    1
    1    1    1    1    1    1
    0    1    1    1    1    1

k =  3
stamp =

  -11    1    3

stamp =

  -11    4    3

stamp =

  -8   4   3

build =

  -11    1   -8    1    1    1
    1    1    4    1    1    1
    0    1    3    1    1    1

k =  5
stamp =

  -8   4   6

stamp =

  -8   7   6

stamp =

  -5   7   6

build =

  -11    1   -8    1   -5    1
    1    1    4    1    7    1
    0    1    3    1    6    1

k =  7
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1) Write a java programming nested while loop where you will declare two numbers one for...
1) Write a java programming nested while loop where you will declare two numbers one for outer loop and the other one for inner while loop, and display the result. (Try using scanner) Steps: 1) Declare the variable of outer loop int and assign value of your choice 2) Declare while condition which outer variable is less the number of your choice 3) Declare variable of inner loop int and assign the value of your choice 4) Declare while condition...
1. How many times the loop below will be executed? What is the value of variable...
1. How many times the loop below will be executed? What is the value of variable counter after the loop? counter = 1 while counter < 7: counter+=2 print(counter) 2. An integer is stored in a variable MyInt. Write the Python if statement to test if MyInt is even number or odd number, and print a message to show “It is even number.” or “It is an odd number”. 3. Complete the python below that asks user to enter the...
Your objective in Problem 2 is to employ Euler's Method to determine what goes wrong when...
Your objective in Problem 2 is to employ Euler's Method to determine what goes wrong when the interval is [ 0, 1 ]. To this end, I want you to create another new script, EulerMethod3, which is intended to approximate the "solution" to the IVP given below.          dy/dx = (1/9)*(y^10)        where.          y(0) = 1.            over the interval. [ 0, 1 ] I was given the code below for a different question, but I don't know how to modify it to solve this...
Do a trace on the binarySearch method below: variable key holds the value 17, and variable...
Do a trace on the binarySearch method below: variable key holds the value 17, and variable list is a reference to an array with these values {9, 20, 23, 28, 33, 38, 42, 48, 54, 61,73}. public static int binarySearch(int[] list, int key) {     int lowIndex = 0;     int highIndex = list.length - 1;     while (highIndex >= lowIndex) {       int midIndex = (lowIndex + highIndex) / 2;       if (key < list[midIndex]){            highIndex = midIndex...
Write a program that finds and prints all of the prime numbers between 3 and X...
Write a program that finds and prints all of the prime numbers between 3 and X (X is input from the user). A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, …). One way to solve this problem is to use a doubly nested loop (a loop inside another loop). The outer loop can iterate from 3 to N while the inner...
Using the Script: function EulerMethod1(n) X = 0 : 1/n : 1 ; Y = zeros(...
Using the Script: function EulerMethod1(n) X = 0 : 1/n : 1 ; Y = zeros( 1, n + 1 ) ; Y(1) = 1 ; for k = 1 : n m = Y(k) ; Y(k + 1) = Y(k) + m*( X(k + 1) - X(k) ) ; end clf plot( X, Y ) Create a new script, which defines the function EulerMethod2. The purpose of EulerMethod2 is to use Euler's Method to approximate the solution to the...
USING PYTHON do all the he problems using while loop , continue and break 1-This problem...
USING PYTHON do all the he problems using while loop , continue and break 1-This problem provides practice using a while True loop.write a function named twoWords that gets and returns two words from a user. The first word is of a specified length, and the second word begins with a specified letter.The function twoWords takes two parameters: an integer, length, that is the length of the first word and a character, firstLetter, that is the first letter of the...
For each pseudo-code function below (after the next ==== line), write a useful loop invariant capturing...
For each pseudo-code function below (after the next ==== line), write a useful loop invariant capturing correctness for the main loop in each of the following programs and briefly argue initialization, preservation, and termination. EXAMPLE PROBLEM: //Function to return the max of an array A Maximum(array of integers A) Local integer integer m m=0 for i = 1 to n if A[i] > m then m = A[i] end function Maximum EXAMPLE SOLUTION: The loop invariant is m = max(0,...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
You may either use SPSS for this problem or carry it out using hand calculations Below...
You may either use SPSS for this problem or carry it out using hand calculations Below are data for n = 20 individuals indicating the resting pulse rate of each person, and whether or not that person regularly exercises. Exercise and pulse rate data Person Resting pulse rate Regularly exercises 1 72 No 2 62 Yes 3 72 Yes 4 84 No 5 60 Yes 6 63 Yes 7 66 No 8 72 No 9 75 Yes 10 60 Yes...