zyBook Chapter 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

Assume i and j are the predefined values for the imaginary component of an imaginary number. 2) What will the command window display after the assignment numB = 4.5 + 2*i? Provide your answer in the form: 2.0000 + 3.0000i. numB =

4.5000 + 2.0000i The command window displays the real and imaginary parts separately.

Select the expression whose parentheses enforce the compiler's evaluation order for the original expression. Note: Using such parentheses is preferable over relying on precedence rules. 7) What is totCount after executing the following?numItems = 5; totCount = 1 + (2 * numItems) * 4; 44 41

41 After (2 * 5) is evaluated, * 4 is evaluated because * has precedence over +.

2) What is x after executing the line x = 5; y = 9; y = x; x = y;

5 y = x assigns y with 5. Then x = y assigns x with y's value, or 5. A proper swap requires a third variable: tmp = x; y = x; x = tmp;

2) What is the next value after 34 in the Fibonacci rabbits example?

55 fnminusTwo becomes fnminusOne or 21, fnminusOne becomes fibonacci or 34, and fibonacci becomes fnminusOne plus fnminusTwo so 21 + 34 or 55.

2) Assume apples currently has the value 5 and oranges the value 9. What is the value stored in apples after the following statement? apples = apples + 1;

6 5 + 1 yields 6

Assume i and j are the predefined values for the imaginary component of an imaginary number. 4) Rewrite the following expression without using the * symbol:numD = 7 + 5*j; numD = (blank);

7 + 5j Omitting the * helps the expression appear like common math notation.

3) Assume apples currently has the value 5 and oranges the value 9. What is the value stored in apples after the following statements? apples = oranges; oranges = oranges + 1;

9 apples gets the value of oranges, or 9. Oranges then gets 9+1 or 10, but that doesn't affect apples.

4) What is the decimal number stored in a string variable delimChar after the following statement: delimChar = "a";

97 The ASCII value of "a" is 97, so 97 is stored in delimChar.

Truncation error

Discarding the least significant digits or a numerical result

3) A double-precision number's range is about 10 times greater than a single-precision number's range. True False

False The range involves 10^308 versus10^38. 10^308 is a number with 308 zeros (100...00 -- 308 zeros) versus 10^38 having 38 zeros. The difference is enormous.

5) The smallest positive number that the default MATLAB floating-point representation can store is 1.1755e-38 True False

False The smallest positive number that be stored as a double precision floating-point number is 2.2251e-308

Rounding error

Finite precision of numerical calculations

Experimental error

Limited accuracy of the measurement apparatus

Assume i and j are the predefined values for the imaginary component of an imaginary number. 5) Rewrite the following expression without using i:numE = 3 + 6i; numE = (blank);

3 + 6j Both i and j can represent an imaginary number. j is preferred.

3) Using notation similar to 6.02e23 and starting with 3.1, write a statement to assign variable wrenchTorque with the value 3,125.99. wrenchTorque = (blank);

3.12599e3 3.12599e3 is equal to 3.12599 x 103

Assume i and j are the predefined values for the imaginary component of an imaginary number. 3) What will the command window display after the assignment numC = 3.2 + 5*j? Provide your answer in the form: 2.0000 + 3.0000i. numC =

3.2000 + 5.0000i The command window displays imaginary numbers using i even if the original assignment used j.

1) Variable num is initially 2. The command num = num * 2 is typed and entered once; then the up-arrow key is pressed followed by enter, three times. What is num?

32 num = num * 2 is executed four times, leading to 2*2 or 4, then 4*2 or 8, then 8*2 or 16, and finally 16*2 or 32.

1) What is the value stored in luckyNumber after these two statements execute? luckyNumber = 7; luckyNumber = 4;

4 The second write to luckyNumber overwrites the first value written into the variable.

3) Does 2 + 3 * 4 - 4 equal 16? Yes No

No * has higher precedence, so 2 + 12 - 4 is 10.

1) Does 2 / 2 * 3 equal 2/6? Yes No

No / and * have equal precedence so are evaluated left to right, thus (2/2)*3, which is 1*3, yielding 3.

2) Does 2 / 3 ^2 equal 4/9? Yes No

No Exponent has higher precedence, so 2/(3^2) is 2/9.

Indicate which numbers are in binary normalized scientific notation. 4) 11.10 × 23 Yes No

No More than one digit cannot precede the binary point.

Indicate which numbers are in decimal normalized scientific notation. 3) 27.8 × 103 Yes No

No Only one digit may precede the decimal point. This number should have been: 2.78 × 104.

Indicate which numbers are in decimal normalized scientific notation. 2) 0.50 × 103 Yes No

No The digit before the decimal point must be 1 to 9. This number should have been: 5.0 × 102.

Indicate which numbers are in binary normalized scientific notation. 3) 0.10 × 23 Yes No

No The leading digit cannot be 0. Thus, in binary, the first digit is always a 1.

Indicate which numbers are in binary normalized scientific notation. 1) 0.0 Yes No

No The number before the decimal point cannot be 0. As such, the value zero cannot be represented in normalized scientific notation.

Indicate which numbers are in decimal normalized scientific notation. 7) 0.0 Yes No

No The number before the decimal point cannot be 0. As such, the value zero cannot be represented in normalized scientific notation.

Which of the following variables are predefined mathematical constants? 5) inf Predefined Not predefined

Not predefined Inf with an upper case I is a predefined constant, but inf is not.

Which of the following variables are predefined mathematical constants? 2) J Predefined Not predefined

Not predefined Lower case j is predefined, but J is not.

Which of the following variables are predefined mathematical constants? 4) e Predefined Not predefined

Not predefined e is not a predefined constant, but the value for Euler's number e can be calculated as exp(1).

1) Using a double precision floating-point representation, the relative accuracy of variable aNum will never exceed eps(1) True False

True The command eps(aNum) finds the absolute accuracy of the valued stored within the variable aNum. The relative accuracy is given by eps(aNum)/aNum and this value will never exceed eps(1)/1 or eps(1).

4) The default MATLAB floating-point representation can represent various numbers from -1.79e+308 to +1.79e+308. True False

True The default MATLAB floating point representation is double precision, which has a range of -1.79e+308 to +1.79e+308.

Which are valid identifiers? 1) r2d2 Valid Invalid

Valid Contains only letters, digits, or underscores, and starts with a letter.

Which are valid identifiers? 4) pay_day Valid Invalid

Valid Contains only letters, digits, or underscores, and starts with a letter.

Which are valid identifiers? 7) y____5 Valid Invalid

Valid Ugly, but allowed; there's little reason though to have multiple adjacent underscores.

Select the expression whose parentheses enforce the compiler's evaluation order for the original expression. Note: Using such parentheses is preferable over relying on precedence rules. 5) x + 1 * y / 2 ((x + 1) * y) / 2 x + ((1 * y) / 2) x+ ( 1 * (y / 2))

x + ((1 * y) / 2) * and / have precedence over + so will be evaluated first. * and / have equal precedence so are evaluated left-to-right, despite what the original spacing implied.

Select the expression whose parentheses enforce the compiler's evaluation order for the original expression. Note: Using such parentheses is preferable over relying on precedence rules. 4) x + y ^ 3 (x + y) ^ 3 x + (y ^ 3)

x + (y ^ 3) ^ has precedence over + so ^ is evaluated first.

3) Given x="a"; y="b"; assign x with the current value of y. End with a semicolon.

x = y; The value in y is simply copied into x.

Given x = 22 and y = 99. What are x and y after the given code? 4) >> tempVal = x; >> x = y; >> y = tempVal; x is 99 and y is 22. x is 99 and y is 99.

x is 99 and y is 22. The swap succeeds, because x's value is saved before being assigned 99, and then that saved value is assigned to y.

Given x = 22 and y = 99. What are x and y after the given code? 3) >> tempVal = x; >> x = y; >> y = x; x is 99 and y is 22. x is 99 and y is 99.

x is 99 and y is 99. The last statement reads x's new value of 99 and assigns it to y. Instead, that statement should read tempVal.

Given x = 22 and y = 99. What are x and y after the given code? 1) >> x = y; >> y = x; x is 99 and y is 22. x is 22 and y is 99. x is 99 and y is 99.

x is 99 and y is 99. x = y assigns 99 to x.y = x then assign x's value, now 99, to y.

Given x = 22 and y = 99. What are x and y after the given code? 2) >> x = y; >> y = x; >> x = y; x is 99 and y is 22. x is 99 and y is 99. x is 22 and y is 22.

x is 99 and y is 99. x = y assigns 99 to x.y = x then assign x's value, now 99, to y.The last x = y assigns 99 to x.

Select the expression whose parentheses enforce the compiler's evaluation order for the original expression. Note: Using such parentheses is preferable over relying on precedence rules. 1) y + 2 * z (y + 2) * z y + (2 * z)

y + (2 * z) * has precedence over +, so is evaluated first.

5) Assign variable phrase with string scalar: Isn't it OK? phrase = (blank);

"Isn't it OK?" "Isn't it OK?" yields the string scalar Isn't it OK?. There is no ambiguity in defining the scalar string when using of the single quote.

1) Assign variable unitName with string scalar: nautical miles unitName = (blank) ;

"nautical miles" A string scalar is surrounded by double quotes.

1) What is val after executing the line num = 6; num = num * 2; val = num + 1;

13 num will assigned with 6 * 2 or 12. Then val will be assigned with 12 + 1 or 13.

Select the expression whose parentheses enforce the compiler's evaluation order for the original expression. Note: Using such parentheses is preferable over relying on precedence rules. 3) x * y * z (x * y) * z x * (y * z)

(x * y) * z The two operators have equal precedence, so the compiler evaluates left-to-right.

Select the expression whose parentheses enforce the compiler's evaluation order for the original expression. Note: Using such parentheses is preferable over relying on precedence rules. 6) x / 2 + y / 2 ((x / 2) + y) / 2 (x / 2) + (y / 2)

(x / 2) + (y / 2) / has precedence over +. The two / are evaluated left-to-right.

Select the expression whose parentheses enforce the compiler's evaluation order for the original expression. Note: Using such parentheses is preferable over relying on precedence rules. 2) z / 2-x (z / 2) - x z / (2 - x)

(z / 2) - x / has precedence over -.

Assume i and j are the predefined values for the imaginary component of an imaginary number. 1) What is the result of numA = i * i?

-1 The key feature of i is that i * i is -1.

1) Expressions must be written on one line. True False

False A long expression can be continued on the next line by using a continuation, which is a sequence of three or more periods "..." at the end of a line.

2) The statement myNum = 0.1 creates a single-precision floating-point number because 0.1 is small enough for single precision. True False

False MATLAB by default creates a double-precision number.

1) The statement myInt = 44 creates an integer variable. True False

False MATLAB by default creates a real variable.

2) The following indicates the expression continues on the next line:x = a + b .. True False

False That line ends with two periods. Three or more indicate continuation. The two periods is a syntax error.

2) Using a double precision floating-point representation, the error in absolute accuracy of the variable aNum will never exceed eps. True False

False The absolute accuracy of a number represented in floating point, which is given by eps(aNum), decreases with the magnitude of aNum. Stated differently, the absolute error gets larger with the magnitude of aNum. It is the relative accuracy that will be bounded by eps(1).

Which are valid identifiers? 2) name$ Valid Invalid

Invalid A $-sign is not allowed; only letters, digits, and underscores.

Which are valid identifiers? 5) pay-day Valid Invalid

Invalid Hyphens are not allowed; only letters, digits, and underscores.

Which are valid identifiers? 6) 2a Valid Invalid

Invalid Must start with a letter

Which are valid identifiers? 3) _2a Valid Invalid

Invalid Must start with a letter.

Which are valid identifiers? 8) switch Valid Invalid

Invalid switch is a keyword and cannot be used as an identifier.

Which of the following variables are predefined mathematical constants? 3) NaN Predefined Not predefined

Predefined NaN is a predefined constant meaning not a number.

Indicate which numbers are in decimal normalized scientific notation. 1) 2.05 × 103 Yes No

Yes All requirements of normalized scientific notation are met: The number is written as a digit (1 to 9), decimal point, fractional part, times 10 to a power.

Indicate which numbers are in binary normalized scientific notation. 2) 1.01 × 23 Yes No

Yes Meets all requirements for normalized scientific notation of a binary number.

Indicate which numbers are in binary normalized scientific notation. 6) 1.01 × 2-3 Yes No

Yes The exponent may be negative.

Indicate which numbers are in decimal normalized scientific notation. 6) 2.05 × 10-3 Yes No

Yes The exponent may be negative.

4) Does 2 ^ 3 ^ 2 equal 64? Yes No

Yes The power operators evaluate left to right, so (2^3)^2 or 8^2, which is 64.

Indicate which numbers are in binary normalized scientific notation. 5) -1.01 × 23 Yes No

Yes The significand may be negative.

Indicate which numbers are in decimal normalized scientific notation. 5) -5.77 × 103 Yes No

Yes The significand may be negative.

Indicate which numbers are in decimal normalized scientific notation. 4) 3.5 Yes No

Yes This number could have also been written as 3.5 × 100. When the exponent is 0, the latter part is often omitted.

5) Does -4 ^ 2 equal -16? Yes No

Yes ^ has higher precedence than -, so -(4^2) is -(16).

5) Write two statements, the first setting apples to 7, and the second setting oranges to apples plus one. Terminate each statement with a semicolon.

apples = 7; oranges = apples + 1; "apples = 7" must be done first, then "oranges = apples + 1" will store 7+1 or 8 into oranges.

4) Write a statement, ending with "- 1;", that decreases the value stored in apples by 1. The output of the statement should be suppressed.

apples = apples - 1; Reads the value of apples, subtracts 1, and writes the result back into apples.

3) Write a variable assignment statement that assigns birdFeeders with the current value of variable stockCount, and prints the value of the variable to the command window.

birdFeeders = stockCount Reads the current value ofstockCountand writes that value intobirdFeeders. The lack of a semicolon causes the value to be printed to the command window.

2) Write a statement that assigns string variable delimChar with the comma character. End with a semicolon.

delimChar = ","; This statement will store the ASCII numerical value of a comma, 44, into the variable delimChar.

1) Write a variable assignment statement that assigns totalPets with 3.

totalPets = 3; or totalPets = 3 The value 3 was assigned to totalPets.

2) Assign celsiusVal with kelvinVal minus 273.15. celsiusVal = (blank);

kelvinVal - 273.15 Reads the value of kelvinVal, subtracts 273.15 from that value, and writes the resulting value to celsiusVal.

2) Write a variable assignment statement that assigns luckyNumber with 7 and suppresses the output to the command window.

luckyNumber = 7; The value 7 was assigned to luckyNumber. The semicolon suppresses printing to the command window.

1) Write a statement that assigns the double precision floating-point variable tempKelvin with 0.0.

tempKelvin = 0.0; Stores the value 0.0 into the variable tempKelvin. If tempKelvin does not exist in the base workspace, the interpreter will first create a new variable named tempKelvin.


Conjuntos de estudio relacionados

Principles of Accounting - Chapter 6 Inventory and Cost of Goods Sold

View Set

Confiscation Act and Emancipation Proclamation

View Set