CSC 1240 Exam 2

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Write a statement using the built-in sin() function that yields the same result as SineWave(1/33,-1.5,0.1,0.067).

-1.5*sin(2*pi*0.1/33 + 0.067) or -1.5*sin((2*pi*0.1/33) + 0.067) Four arguments are specified in the call to SineWave(), therefore all default values are replaced with the values in the input list

Assume the function MoveBallRight() above is defined in addition to the global variables. What is the value of ballPositionX after executing the following: ballPositionX = -10; ballPositionY = 0; result = MoveBallRight(-7);

-17 The number -7 is passed as the argument deltaX to MoveBallRight() and is added to the original value of ballPositionX, -10.

To solve the equation 2+2sin⁡(x)=x^3 with fzero, the anonymous function that must be used is anonFun = @(x) x^3 ....fill in ..... ;

-2-2*sin(x)or-2*sin(x)-2 The solution will be the zeros of the function x^3-2-2sin(x)=0.

In the function SineWave() above, what is the value of local variable sinePhase in the expression for sineResult for the function call SineWave(0.76, -1.5, pi/4)? Write your answer to two decimal places.

0.00 Three arguments are specified in the call to SineWave(). After the switch statement executes, only sinePhase retains its default value of 0.00.

global ballPositionX; global ballPositionY; In the definition of function MoveBallUp(), which only updates the vertical position of the ball, how many global variables must be declared? Write the answer as 1, 2, or 0.

1 ballPositionY must be declared as a global variable within the function definition so that the correct variable is being updated. Both global variables need not be declared if they are not both being accessed by the function.

The roots of the polynomial 3x^2+x^3+6x+2 are calculated with the function call: theroots=roots([..fill in ...])

1, 3, 6, 2 The coefficients of 3x^2+x^3+6x+2 are [1,3,6,2]

What is the value of num after the following loop terminates? num = 1; while( num < 10 ) num = 2 * num; end

16 num starts with the value 1. After the first iteration, it is assigned the value 2, then 4, etc. until it reaches the first value greater than 10, which is 16.

Assume user input for the GCD program results in numA = 18 and numB = 12. What is numA before the first Euclid algorithm loop iteration?

18

x=5; y=18; while (y >= x) fprintf('%d ',y); y = y - x; end

18 13 8 Note that there is a space after each number, including after the last number.

Assume user input for the GCD program results in numA = 18 and numB = 12. How many loop iterations will the algorithm execute?

2 The loop does not enter a third iteration because numA == numB (6 == 6), so execution proceeds below the while loop and thus 6 is output as the GCD.

Consider the following script that calls the modified function UpdateBalance() above: clear all; UpdateBalance(1000.00) UpdateBalance(-23.78) clear all; UpdateBalance(900.00) What is the value of numTrans immediately before the second clear statement?

2 UpdateBalance() is called twice before the second clear statement, so numTrans is first initialized to 1 and then incremented once to 2.

What is the value returned by calling the Fibonacci() function above with input 13?

233 Fibonacci(13) = Fibonacci(12) + Fibonacci(11) = 144 + 89, as shown in the example above, therefore the answer is 233.

How many times is the Fibonacci() function called when given the input 4? Do not include the initial function call Fibonacci(4).

4 Fibonacci(4) = Fibonacci(3) + Fibonacci(2). Fibonacci(2) returns 1. Fibonacci(3) = Fibonacci(2) + Fibonacci(1), and Fibonacci(1) returns 1. Thus there is one call Fibonacci(3), one call Fibonacci(1), and two calls Fibonacci(2), for a total of 4 recursive calls.(

Given the following while loop, what is the value assigned to variable z for the given values of variables a, b and c? mult = 0; while a < 10 mult = b * a if mult > c break; end a = a + 1 end z = a

5 z=5 In the first iteration, and a is 4, so mult is assigned 20 (4*5). 20 > 20 is false, so a is incremented by 1. In the second iteration, a is 5, so mult is assigned 25 (5*5). 25 > 20, so the if branch executes, causing a break from the loop. Thus, a's value of 5 is assigned to z.

Given the following code, how many times will the fprintf statement execute? i1 = 1; while (i1 < 19) i2 = 3; while (i2 <= 9) fprintf('%d%d ', i1, i2); i2 = i2 + 3; end i1 = i1 + 10; end

6 The outer loop will iterate 2 times for i1 = 1, 11. While the inner loop will iterate 3 times for i2 = 3, 6, 9. Therefore 2 * 3 = 6.

Assume user input for the GCD program results in numA = 18 and numB = 12. What is numA after the second and before the third iteration?

6 numB > numA, so the first branch is taken leaving numA unchanged.

Assume user input for the GCD program results in numA = 18 and numB = 12. What is numB after the second and before the third iteration?

6 numB > numA, so the first branch is taken setting numB = numB - numA.

Assume user input for the GCD program results in numA = 18 and numB = 12. What is numA after the first and before the second iteration?

6 numB is < numA, so the else branch is taken setting numA = numA - numB.

Using the iterative bisection approach described in the previous example that finds the first zero of J0(x), find the third zero of J0(x) that occurs in the range 8<x<10. Enter the answer to at least four decimals.

8.6537 Calculate the function values over the interval using coarse interval steps, look for sign change, get small interval, decrease the interval steps, and repeat the process.

What is the final value of acctBalance after the script above executes? Write your answer to two decimal places.

900.00 The clear statement erases all variables, including persistent variables, from memory. The first call to UpdateBalance() after the second clear statement initializes acctBalance to 900.00.

(CD^T)^T

=DC^T

(C^T*D)^T

=D^T*C

recursive function

A function that calls itself is a

invertible or nonsingular matrix

A square matrix A is _______________ if there exists a unique matrix A^−1 such that AA^−1=I and A^−1*A=I, where I is the identity matrix. A matrix is __________ only if det(A) is not zero.

local variable

A variable defined in a function has a local scope and is called a

row-echelon matrix

All the non-zero rows are above any all-zero rows (a.k.a. all-zero rows are at the bottom of the matrix). The leading coefficient of a non-zero row is always to the right of the first non-zero entry of the row above. All the column entries below the pivot are zeros.

A = ( -j 2+j -1+2j. 1+j) After the command newMatrix =A.' the (1,2) matrix entry will be 2−j. True False

False

A pivot can be zero. True False

False

A plane is formed by two non-parallel vectors. Multiplying each vector with a different scalar and adding the result can create a vector in a new plane. True False

False

Gaussian elimination will produce a unique row-echelon matrix. True False

False

A matrix has an inverse if the determinant is zero. True False

False A matrix has an inverse if the determinant is non-zero.

A row-reduced echelon square matrix will be upper triangular. True False

False A row-echelon square matrix can have a row with all zeros at the bottom of the matrix, which is not an upper triangular matrix.

The matrix is a unit triangular matrix: (200 110 aa1) True False

False All the diagonals must be one.

In a linear set of equations, replacing a row with the the linear combination of the original row subtracted from the original row is an allowable elementary row operation since the solution vector remains the same. True False

False An elementary row operation does not change the solution of the set of equations. The operation described would effectively remove an equation from the linear set. Therefore, this operation is not an allowable elementary row operation.

In the bisection technique the functions must be calculated at uniform intervals True False

False Calculating the function values at uniform interval is the simplest, but not a requirement. In practice little is to be gained by using a nonuniform interval.

An elementary matrix can be rectangular. True False

False Elementary matrices always are square.

A row permutation matrix is an identity matrix with columns exchanged. True False

False Exchanging the columns will produce a column-exchange permutation matrix. A row-exchange permutation matrix is an identity matrix where the rows have been exchanged.

The matrix product AA^T is not always allowed. True False

False For an (m×n) matrix A, then A^T will be a (n×m) matrix. The multiplication is always allowed.

Gaussian elimination will always produce a row-echelon matrix. True False

False Guassian elimination will only produce a row-echelon matrix if a solution is possible. If a pivot is not available with a row exchange, the elimination stops and a solution is not possible.

Changing the sequence of equations in a linear system will scramble the order of the entries of the solution vector. True False

False If the original matrix equation is Ax=b, changing the order of the equations will produce a new coefficient matrix in which the rows are exchanged, but the solution vector x remains unchanged. The values and the sequence of entries in the vector x remain the same.

An inverse for a square matrix always exist. True False

False It is possible for a square matrix to not have an inverse.

Two matrices can be added if the first is a (2×3) matrix and the second is a (3×2) matrix. True False

False Matrices can be only added if the matrices have the same dimensions, meaning the matrices have the same number of rows and columns. The matrices in this question have opposite dimensions.

The matrix product AB always will equal the BA True False

False Matrix multiplication does not commute.

Bisection technique make an estimate of the derivative to find a zero True False

False Only function values are used, and the algorithm looks for a change in sign in the function values

A rectangular matrix has an inverse. True False

False Only square matrices can have inverse matrices.

A rectangular matrix has a determinant. True False

False Only square matrices have determinants.

To solve a set of linear equations with back substitution in MATLAB requires several lines of code written by the user. True False

False Provided the coefficient matrix is upper triangular, the backslash operator will realize that back substitution must be used.

For a matrix A and a row-permutation matrix P, the matrices A and PA will have different LU decompositions. True False

False The LU decomposition of a matrix is independent of the order of the rows.

In order to solve Ax=b for different b vectors, a different LU decomposition of A must be performed for each b vector. True False

False The LU decomposition only needs to be performed once. Then solutions for different b vectors are calculated using the L and U triangular matrices.

The determinant of a 4 x 4 array is a vector. True False

False The determinant of any matrix is a single number.

In MATLAB to solve Ax=b with Gauss-Jordan, the function call is rref(A). True False

False The input to rref must be the augmented matrix [A|b].

Given a linear set of equations Ax=b, where A is a square matrix, calculating the inverse of the matrix A is an efficient way to solve the set of equations numerically. True False

False The inverse of the matrix A should never be numerically calculated. Other numerical techniques are more efficient for solving a linear set of equations.

If A has the same number of rows as the number of columns in B, then the product AB is allowed. True False

False The number of columns of A must be equal to the number of rows of B.

Pivots always appear in consecutive columns in an echelon matrix. True False

False The only requirement is that the pivots appear in consecutive rows.

The product of (1×4) matrix with a (4×1) matrix will result in in a matrix with more than one entry. True False

False The product of an (m×k) matrix and a (k×n) matrix will produce a (m×n) matrix. In this case, m=n=1, only one entry is produced.

The name of an MATLAB function can be directly passed. True False

False The reference to the function must be a handle to the function, and so the name of the MATLAB function will not work. That is an @ sign needs to be added. For example: fanon @(x) sin(x); fzero(fanon, guesses).

All elementary row matrices will have ones on the diagonal. True False

False The row-exchange elementary matrices do not have ones on the diagonal.

The name of a function written by a user can be directly passed. True False

False The same conditions hold as for an MATLAB function. For an external function customFun, an @ sign needs to be added. For example: fanon @(x) customFun(x); fzero(fanon, guesses)

Two matrices are row equivalent if the matrices have the same number of rows. True False

False Two matrices are row equivalent if one can be changed to the other by a sequence of elementary row operations.

The following matrix with complex numbers is Hermitian: (1 j j 1 ) True False

False the off-diagonal elements should be the conjugate of each other. The matrix would be Hermitian if one off-diagonal entry is j and the other -j.

Assuming the function FunRatio() defined above works correctly, write a statement using FunRatio() to calculate the tangent of pi/3.

FunRatio(@sin,@cos,pi/3) Tangent is equivalent to the ratio of sine over cosine. FunRatio() must be called with function handles that indicate these two built-in functions.

function workspace

Functions do not share the base workspace. Every function has a separate _____________ that is isolated from other workspaces.

(a*b^)b^

Gives a vector of length acos⁡(theta) in the direction of b.

a^xb^

Gives a vector that is perpendicular to the two vectors a and b

b*a^

Gives the magnitude of the projection of vector b onto vector a

singular matrix

If A^−1 does not exist, the matrix A is

common

If three planes never intersect at a __________ point, line, or plane, a solution does not exist and the linear system is inconsistent.

(AB)^T = A^T*B^T

Invalid matrix operation (AB)T= A^T * B^T

divide-and-conquer

Merging continues with successively larger sub-lists until the last two sub-lists are merged to form the final, fully-sorted list. Sorting using this ________________ approach can be implemented using a single function that calls itself.

Scalar multiplication

Multiplying a vector a by a scalar alpha, indicated by alpha*a, stretches the vector by alpha. If the alpha is positive, the vector direction of alpha*a is the same as a. If the scalar is negative, the direction of alpha*a becomes opposite of the vector a.

Complete the assignment statement in the else branch to compute the factorial recursively. else % RECURRENCE numFact = inputNum *__________________; end end

MyFactorial( inputNum - 1 ) The factorial of a number is equal to the number multiplied by the factorial of the number minus one.

The row-reduced echelon matrix R produced by Gauss-Jordan is a matrix decomposition of the matrix A in Ax=b. True False

The Gauss-Jordan method does not decompose the matrix A. Gauss-Jordan solves Ax=b

elementary row exchange matrix

The inverse E^−1 equals E.

elementary row replacement matrix

The inverse E^−1 is obtained by replacing the non-unity non-zero value s in E by −s.

elementary row scaling matrix

The inverse E^−1 is obtained by replacing the non-unity non-zero values in E by 1/s.

pivot

The leading coefficient in a non-zero row is the _________ of the row

bisection method

The simplest zero finding technique is

numberMoles = 10; temperatureCelsius = 37; volumeCubeMeter = 1; pressureOut = IdealGasPressure(numberMoles, temperatureCelsius, volumeCubeMeter) function [ pressurePascal ] = IdealGasPressure(numMoles, tempCelsius, volCubemeter) % Inputs: volume is measured in cubic metres, % numMoles is measured in moles, % temp in Celsius % Output: pressure is measured in pascals absTemp = tempCelsius + 273.15; idealGasConst = 8.314; % Units Joules / (Kelvin * mol) pressurePascal = (numMoles * idealGasConst * absTemp) / volCubemeter; end numberMoles:

The variable is in the base workspace.

numberMoles = 10; temperatureCelsius = 37; volumeCubeMeter = 1; pressureOut = IdealGasPressure(numberMoles, temperatureCelsius, volumeCubeMeter) function [ pressurePascal ] = IdealGasPressure(numMoles, tempCelsius, volCubemeter) % Inputs: volume is measured in cubic metres, % numMoles is measured in moles, % temp in Celsius % Output: pressure is measured in pascals absTemp = tempCelsius + 273.15; idealGasConst = 8.314; % Units Joules / (Kelvin * mol) pressurePascal = (numMoles * idealGasConst * absTemp) / volCubemeter; end pressureOut

The variable is in the base workspace.

numberMoles = 10; temperatureCelsius = 37; volumeCubeMeter = 1; pressureOut = IdealGasPressure(numberMoles, temperatureCelsius, volumeCubeMeter) function [ pressurePascal ] = IdealGasPressure(numMoles, tempCelsius, volCubemeter) % Inputs: volume is measured in cubic metres, % numMoles is measured in moles, % temp in Celsius % Output: pressure is measured in pascals absTemp = tempCelsius + 273.15; idealGasConst = 8.314; % Units Joules / (Kelvin * mol) pressurePascal = (numMoles * idealGasConst * absTemp) / volCubemeter; end temperatureCelsius

The variable is in the base workspace.

numberMoles = 10; temperatureCelsius = 37; volumeCubeMeter = 1; pressureOut = IdealGasPressure(numberMoles, temperatureCelsius, volumeCubeMeter) function [ pressurePascal ] = IdealGasPressure(numMoles, tempCelsius, volCubemeter) % Inputs: volume is measured in cubic metres, % numMoles is measured in moles, % temp in Celsius % Output: pressure is measured in pascals absTemp = tempCelsius + 273.15; idealGasConst = 8.314; % Units Joules / (Kelvin * mol) pressurePascal = (numMoles * idealGasConst * absTemp) / volCubemeter; end volumeCubeMeter

The variable is in the base workspace.

numberMoles = 10; temperatureCelsius = 37; volumeCubeMeter = 1; pressureOut = IdealGasPressure(numberMoles, temperatureCelsius, volumeCubeMeter) function [ pressurePascal ] = IdealGasPressure(numMoles, tempCelsius, volCubemeter) % Inputs: volume is measured in cubic metres, % numMoles is measured in moles, % temp in Celsius % Output: pressure is measured in pascals absTemp = tempCelsius + 273.15; idealGasConst = 8.314; % Units Joules / (Kelvin * mol) pressurePascal = (numMoles * idealGasConst * absTemp) / volCubemeter; end absTemp

The variable is in the function workspace of IdealGasPressure.

numberMoles = 10; temperatureCelsius = 37; volumeCubeMeter = 1; pressureOut = IdealGasPressure(numberMoles, temperatureCelsius, volumeCubeMeter) function [ pressurePascal ] = IdealGasPressure(numMoles, tempCelsius, volCubemeter) % Inputs: volume is measured in cubic metres, % numMoles is measured in moles, % temp in Celsius % Output: pressure is measured in pascals absTemp = tempCelsius + 273.15; idealGasConst = 8.314; % Units Joules / (Kelvin * mol) pressurePascal = (numMoles * idealGasConst * absTemp) / volCubemeter; end numMoles

The variable is in the function workspace of IdealGasPressure.

numberMoles = 10; temperatureCelsius = 37; volumeCubeMeter = 1; pressureOut = IdealGasPressure(numberMoles, temperatureCelsius, volumeCubeMeter) function [ pressurePascal ] = IdealGasPressure(numMoles, tempCelsius, volCubemeter) % Inputs: volume is measured in cubic metres, % numMoles is measured in moles, % temp in Celsius % Output: pressure is measured in pascals absTemp = tempCelsius + 273.15; idealGasConst = 8.314; % Units Joules / (Kelvin * mol) pressurePascal = (numMoles * idealGasConst * absTemp) / volCubemeter; end pressurePascal

The variable is in the function workspace of IdealGasPressure.

A matrix that is both upper and lower triangular is a diagonal matrix. True False

True

Scalar multiplication is performed on each component separately. True False

True

The direction of vector*scalar will always be parallel with vector. True False

True

Vector addition is performed component wise. True False

True

A^T equals A^H if all the matrix elements are real. True False

True A complex conjugate of a real number has no effect on the real number.

For an (m×n) matrix A, the size of the transpose of A will be (n×m). True False

True A^T will be (n×m)

The product of a (3×2) matrix and any matrix with 2 rows can be calculated; i.e. the number of columns in the second matrix does not matter. True False

True As long as the inner dimensions match, the multiplication is allowed.

A consistent linear system of equations may have an infinite number of solutions. True False

True By definition, a consistent system of linear equations must have at least one solution. An infinite number of solutions meets this requirement.

An inconsistent linear system has no solution. True False

True By definition, an inconsistent system of linear equations does not have a solution.

Elementary row operations on an augmented matrix never change the solution set of the associated linear system. True False

True Elementary row operations do not change the solution of the augmented matrix since the coefficient and row-reduced matrices are row equivalent.

The matrix product AA^T will produce a square matrix True False

True For an (m×n) matrix A, then A^T will be a (n×m) matrix, and the multiplication will produce an (m×m) matrix, which is a square matrix.

The location can be given as a bracket of two values where the sign of the function changes. True False

True If a bracket of values is given describing a range where the zero occurs, then the sign of the function at the bracket values must be different

If a solution is possible, Gaussian elimination can always produce a row-echelon matrix. True False

True If a solution is possible, row replacements and row exchanges will always produce a row-echelon matrix.

Pivots always appear in consecutive rows in an echelon matrix. True False

True In an echelon matrix, the top rows will have the pivots. The rows with pivots will be the non-zero rows. If additional rows exist, the rows will be filled with zeros and are called the zero rows. The zero rows will be below the row with pivots ( the non-zero rows).

The MATLAB solution of Ax=b is [L,U]=lu(A); c=L\b; x=U\c; and is equivalent to [L,U]=lu(A); x=U\(L\b); . True False

True L\b obtains a solution for the vector c with forward substitution, and x=U\c obtains a solution for the vector x with backward substitution. The second option does not explicitly calculate c; however, this variable is not used in subsequent calculations, and so can be overwritten.

Two matrices can be added if both are (2×4) matrices. True False

True Matrix addition is an element by element operation, and therefore the two matrices must have the same number of rows and the same number of columns, meaning the matrices have the same dimensions.

Every elementary row operation is reversible. True False

True Row exchanges can be reversed. Multiplying by a constant is reversed by multiplying by the constant's inverse. If a row one is added to row two and replaces row two, then this operation can be reversed by subtracting row one from row two to get back to the original row two.

Row equivalent coefficient matrices A and U will produce the same solution for Ax=b and Ux=c. True False

True Since elementary row operations connect A and U, the two matrices will produce the same solution.

A = ( -j 2+j -1+2j. 1+j) After the command newMatrix =A' the (1, 2) matrix entry will be −1−2j.

True The ' operator swaps the rows and columns while also taking the complex conjugate of the array elements. The (1, 2) matrix entry will be the complex conjugate of −1+2j which is −1−2j.

The Gauss-Jordan solution of Ax=b produces Rx=d where R is the row-reduced matrix. R will be unique. True False

True The Gauss-Jordan method produces a unique R matrix.

Bisection technique looks where a function changes sign True False

True The bisection technique is a conquer and divide approach to locate zeros. If the sign of a function changes in an interval, there must be a zero, or maybe more than one zero, within the interval.

An elementary row-replacement matrix will always have ones on the diagonal. True False

True The diagonal entries always remain one in a row-replacement matrix since the i element multiplies the i row and a the i row is always multiplied by 1. The row replacement always adds or subtracts a multiple of another row (such as not equal to i to the i-th row.

An elementary row-replacement matrix that is used to make entries zero in rows below a pivot will always be a lower triangular matrix. True False

True The non-unity values of the row-replacement matrix must be in the lower rows, making the matrix lower triangular.

If matrix A is a lower triangular matrix and an elementary row-replacement matrix, then A's inverse is also a lower triangular matrix. True False

True The only change in obtaining the inverse is changing the sign on the non-unity non-zero element.

A row-exchange permutation matrix always contains ones and zeros. True False

True The permutation matrix is an identity matrix where the rows have been exchanged.

The product of a (4×4) matrix with a (4×1) matrix will result in in a column matrix . True False

True The product of a (4×4) matrix with a (4×1) matrix will produce a (4×1) matrix. This is a direct application of the rule that multiplying an (m×k) matrix by a (k×n) matrix produces an (m×n) matrix .

The name of an anonymous function can be directly passed. True False

True The reference to the function must be a handle to the function. When an anonymous function is declared, a handle to the function is automatically created. For example, an anonymous function created with tanFun = @(x) tan(x-0.1); creates a handle to the expression the tan(x-0.1), and the call is then fzero(tanFun, guesses).

Every linear set of equations may have no solution, one solution, or an infinite number of solutions. True False

True There are three options: i) no solution, ii) a unique solution, iii) infinitely many solutions.

The back substitution solution method for Ax=b only works if the matrix A is an upper triangular matrix.

True Upper triangular matrix form is a requirement for back substitution.

The location can be given as a single value. True False

True Yes, a single value can be given, however in some cases the algorithm will not converge. It is better to provide a bracket.

The matrix is a permuted triangular matrix: (210 231 100) True False

True the rows can be reordered to 100 210 231

recursion

Using a function that calls itself is known as

empDistribution = [ [73,75,81] ; [85,75,69] ; [75,81,84] ]; aptNumbers = 1:9; extractTemps=tempDistribution(extractAprNumbers') The variable extractTemps is equal to? [81; 81] [81, 81] [75; 81] [75, 81]

[81; 81] A column is returned, with entries at all the true positions in extractAprNumbers

To perform an LU decomposition on the matrix A, place the upper triangular matrix in the variable U, and the lower triangular matrix in the variable L, complete the following statement: [_____, _____, P] = _____(A); Enter the complete expression.

[L, U, P] = lu(A); The MATLAB function is lu, the input argument is the matrix of interest, and the sequence of output arguments is the lower triangular matrix, the upper triangular matrix and the permutation matrix. The permutation matrix could be left off if information about a permutation is not required.

tempDistribution = [ [73,75,81] ; [85,75,69] ; [75,81,84] ]; aptNumbers = 1:9; extractAprNumbers = aptNumbers > 5 & ... aptNumbers < 8 The variable extractAprNumbers is equal to? [false, false, true, false, false, false, false, true, false] [false, false, false, false, false, true, true, false, false] [[false, false, true]; [false, false, false]; [false, true, false]] [false; false; true; false; false; false; false; true; false]

[false, false, false, false, false, true, true, false, false] A logical row array is defined with the true values in positions 6 and 7

The dot product produces a number a vector

a number The dot product is also known as the scalar product, since the result is a scalar.

Provide a statement to make a vector into a unit vector equivalent to alpha^=a/‖a‖ Use the norm function and the variable a and create a new variable aUnit. aUnit=

a/norm(a,2) norm(a,2)gives the magnitude of a vector. The statementnorm(a)is equivalent tonorm(a,2).

Given a height argument, calculate the area of a triangle assuming the base is 7.98. ______________________; CalcTriArea = @( height ) 0.5 * base * height ;

base = 7.98 The variable base is assigned the value 7.98 before being used in the function definition.

Iterate until c is equal to the variable n. while (_________) end

c ~= n "c == n" would be incorrect. Note the word "until" rather than "while" in the question, meaning to loop while c is not n. "~(c == n)" would also be correct using two operators.

With linear indexing, what is the integer index array to display the cMat(1,1) and the cMat(2,2) as a column? % Result should be a column array resultingColumn =

cMat([1; 4]) The format is cMat([ integerColArray ]) with two elements in integerColArray.

With row-column indexing, what is the logical index array to display both the cMat(1,1) and the cMat(2,2) as a row? % Result should be a row array resultingRow =

cMat([[true, false]; [false, true]])' The format is cMat([ logical2DArray ])' where the transpose is needed to convert the output column to row.

With linear indexing, what is the logical index array to display both the cMat(1,1) and the cMat(2,2) as a row? % Result should be a row array resultingRow =

cMat([true, false, false, true]) The format is cMat([ logical1DRowArray ]) with four elements. Array elements corresponding to cMat(1,1) and cMat(2,2) are marked as true.

elementary row operations

can be performed on a set of linear equations without changing the solution vector X (both the values and the sequence of the vector elements): interchanging rows, scaling a row by a constant (Ex: multiplying by a constant), and replacing a row with a linear combination of the original row and a multiple of any other row.

Row-column integer indexing: cannot be used to access elements in 2D arrays. can return a 2D array. returns only logical values.

can return a 2D array. Multiple rows and columns can be accessed in a 2D array using row-column integer indexing.

typing __________ from the command line will interrupt the program execution (exiting the infinite loop), and allow the programmer to enter a new command

ctrl-c

Provide a statement to calculate the cosine of the angle (cosθ) between vectors a and b. Use the dot function and the variables a and b and create a new variable cosAngle. cosAngle =

dot(a/norm(a,2),b/norm(b,2)) The dot product is equal to product of the magnitude of the two vectors times the cosine of the angle between the vectors. If vectors are unit vectors, then the dot product equals the cosine of the angle between the two unit vectors.

Gauss-Jordan

elimination produces a row-reduced echelon matrix R

Root finding algorithms are capable of locating regions in which the zeros occur True False

false The majority of root finding algorithms must be given estimates of where the zeros of interest are. The one exception, which will be discussed later, is if the roots of a polynomial are calculated.

Complete the statement below so that the function returns the ratio of two input argument functions evaluated at scalar value xVal. function [ result ] = FunRatio( numerFun, denomFun, xVal ) % Calculates the ratio of two functions % numerFun(xVal)/denomFun(xVal). % numerFun and denomFun are function handles. result =_______________________________ ; end

feval(numerFun, xVal) / feval(denomFun, xVal) feval() is used to evaluate each of the functions separately with argument xVal. Then, an arithmetic expression is used to compute the ratio.

vector +infinity norm

finds the maximum of the absolute values in an array

vector ~ infinity norm

finds the minimum of the absolute values in an array

Iterate 100 times.

for The iterations are known before the loop, so use "for i = 1:100"

elementary row-scaling matrix

for an (m×n) matrix A can be used to multiply row i by scaling factor s and is obtained by taking an (m×m) identity matrix I and multiplying the diagonal element of row i by s.

global ballPositionX; global ballPositionY; Fill in the blank below so that the correct global variable is declared. function [] = MoveBallRight( deltaX ) _________________________; % global variable ballPositionX = ballPositionX + deltaX; end

global ballPositionX ballPositionX must be declared as a global variable within the function definition so that the correct variable is being updated.

GCD

greatest common divisor, the largest positive integer that divides into the numbers without producing a remainder

hermitian matrix

has is symmetric with complex number entries that are complex conjugates of each other above and below the main diagonal.

Which statement will display a column of labels? hiCostDataLabels = dataLabels( hiCostIdx',:) hiCostDataLabels = dataLabels( hiCostIdx );

hiCostDataLabels = dataLabels( hiCostIdx',:) Row-column indexing is used, and MATLAB expects a 1D array. It can be either a row array or a column array. Also, hiCostDataLabels = dataLabels( hiCostIdx,:) is correct.

base workspace

holds variables created during an interactive MATLAB® session.

Loop iterates over the odd integers from 0 to 9 (inclusive). i = 1; while ( i <= 9 ) i = ______; end

i + 2 "i = i + 2" iterates over 1, 3, 5, 7, and 9.

Loop iterates over multiples of 5 from 0 to 1000 (inclusive). i = 0; while ( i <= 1000 ) i = ______ ; end

i + 5 The while loop could also be "while ( i <= 1001 )". A common error is to use "i = i * 5", which will yield 0, 0, 0, ... rather than 0, 5, 10, 15, ... (and even if start with i=1 would yield 1, 5, 25, 125, ...)

Loop iterates from 212 to 32 (inclusive). i = 212; while ( i >= 32 ) i = ______; end

i - 1 The while loop could also be "while ( i > 31 )"

Iterate with i over the even integers from 4 to 20 (inclusive). for_______________ end

i = 4:2:20

square matrix

if m=n, meaning the number of rows and columns are the same

rectangular matrix

if m≠n, meaning the number of rows and columns are different

Consider this partially-complete function definition that calculates the factorial of a number recursively when answering the two questions below. Complete the logical expression for the if statement for the base case such that MyFactorial will return an answer when called with any non-negative argument. function [ numFact ] = MyFactorial( inputNum ) % Recursively calculate factorial of inputNum, % where inputNum is non-negative. if ( (inputNum == 1) || (____________________________________) ); numFact = 1;

inputNum == 0 If inputNum is equal to 0, then 1 is returned, consistent with the mathematical definition of factorial.

size of matrix

is (m×n), where m is the number of rows and n the number of columns

anonymous function

is a custom function defined directly in the workspace or in a program file

identity matrix

is a diagonal matrix with ones on the main diagonal. An identity matrix will be indicated by I

nested function

is a function defined within another function, known as the parent function can use variables defined in the parent function without explicitly passing those variables as arguments

functioon handle

is a special class of variable that is a pointer to another function is created by placing an @ symbol in front of a function name, and then using the assignment operator.

row-reduced echelon matrix

is a specific row-echelon matrix with: i) all the pivots equal to 1, and ii) the pivots are the only non-zero entry in the column.

triangular matrix

is a symmetric and all the entries are zero either above or below the main diagonal.

diagonal matrix

is a symmetric matrix where only the diagonal contains non-zero elements. All other entries are zero

unit triangular matrix

is a triangular matrix with ones on the main diagonal.

pointer

is a variable that points to a location in memory where data is stored. In the case of a function handle, the "data" is the MATLAB® code that defines the function.

matrix determinant

is only defined for square matrices.

symmetric matrix

is square matrix that is symmetric across the main diagonal.

tridiagonal matrix

is symmetric and has only non-zero entries on the main diagonal and the two adjacent diagonals.

pivot column

is the column that contains a pivot

augmented matrix

is the columns of the coefficient matrix adjoined with the right-hand coefficient column vector starts Gaussian elimination process

conjugate transpose

is the transpose of the matrix's complex conjugate. The conjugate transpose of A is indicated as A^H

A special type of integer array used to extract values from a 2D array by using a single index for each indexed array element.

linear indexing array

loop body

list of statements within the loop

Write a statement equivalent to the function call feval( @log,7.47 ):

log(7.47) @log is the function handle for the built-in function log(), the natural logarithm.

Any array consisting of logicals (i.e., true and false values).

logical array

A special type of logical array used for indexing.

logical indexing array

When an (m×n) matrix b and an (A×1) column vector b are multiplied, what is the length of Ab is equal to?

m A matrix product is only allowed if the number of columns of the first matrix are the same as the number of rows of the second matrix. For Ab the length of the vector b must equal the number of the columns in the array A. Since an(m×n)matrix is multiplied by a(n×1)vector, the length of the resulting vector is m

full matrix

most of the entries are non-zero

sparse matrix

most of the entries are zero.

When a (1×m) row vector c and an (m×n) matrix A are multiplied, the length of cA is equal to?

n A matrix product is only allowed if the number of columns of the first matrix are the same as the number of rows of the second matrix. For cA the length of the vector s must equal the number of the rows in the array�. Since a(1×m)vector is multiplied with an(m×n)matrix, the length of the resulting vector is n.

Complete the following function definition that calculates the volume of a sphere or a cylinder based on the number of arguments the function is called with. function [ volResult ] = SolidVolume( inRadius, inHeight ) % Calculates the volume of a sphere if given only one % argument (radius) and a cylinder if given two (radius & % height). switch (_____________________________________________________________) case 1, volResult = (4/3) * pi * inRadius^3; case 2, volResult = pi * inRadius^2 * inHeight; otherwise, disp('Incorrect number of arguments!'); end end

nargin nargin evaluates to the number of arguments that the function was called with.

declaring a global

needs to go beyond the limitations of the function input list to extend the scope of a variable. For example, a programmer may need to write a program that requires many different functions to interact with each other. In such a case, a programmer may decide to extend the scope of a variable by

With row-column indexing for 2D arrays, using a row integer indexing array and a column integer indexing array, what is the command to display both the cMat(1,1) and the cMat(2,2) as a column? % Result should be a column array resultingColumn =

no answer Row-column indexing for 2D arrays with a row integer indexing array and a column integer indexing array cannot access multiple elements in a 2D array that are on array element positions that do NOT share common rows and columns.

Provide a statement to calculate the sine magnitude of the angle (sineθ) between vectors a and b. Use the cross function and the variables a/norm(a,2) and b/norm(b,2). sinAngle =

norm(cross(a/norm(a,2),b/norm(b,2)),2) The cross product of two non-perpendicular unit vectors produces a vector that is perpendicular to the two unit vectors and is equal to the sine of the angle between the two unit vectors. Therefore the magnitude (norm) of the cross product provides the sine magnitude.

Write a statement that increments variable numTrans by one for each call to UpdateBalance() after the first call. % The first time the function is called acctBalance will be [], so % updateAmt should be assigned as an initial balance. Also, the % number of transactions should be initialized. if isempty(acctBalance) acctBalance = updateAmt; numTrans = 1; else acctBalance = acctBalance + updateAmt; ___________________________________________________________; end fprintf('Executing Transaction No. %d\n',numTrans); curBalance = acctBalance; end

numTrans = numTrans + 1 The else branch is executed when the function is called after the first time, so 1 is added to numTrans here.

scope

of a variable refers to the parts of a program that can access that variable's value.

topMounts = [ 8848, 8611; % Asia (Everest, K2) 6962, 6893; % S. America (Aconcagua, Ojos del Salado) 6194, 5959 ] % N. America (McKinley, Logan) What result is returned by evaluating the following: outlierIdx = (topMounts > 8700) | (topMounts < 6900); outlierHts = topMounts(outlierIdx) outlierHts =8848;6194;5959;6893 outlierHts =8848;6194;6893;5959 outlierHts = 8848 6194 6893 5959 outlierHts = 8848 6194 5959 6893

outlierHts =8848;6194;6893;5959 The order is correct. Result is returned in linear indexing order.

Write a statement to declare the variable numTrans as a variable that remains in memory after UpdateBalance() returns. function [ curBalance ] = UpdateBalance( updateAmt ) % UpdateBalance Updates bank account balance stored as % persistent variable % Inputs: updateAmt - amount to be added to balance; % debits use negative values % Outputs: curBalance - current account balance persistent acctBalance; _______________________________________;

persistent numTrans numTrans must be declared a persistent variable to maintain its value between function calls, similar to the variable acctBalance.

dot product

produces a scalar

cross product

produces a vector

global

programmer declares a variable using the keyword

Each element in the logical indexing array indicates whether an array element in the indexed array should be

returned (true) or not returned (false)

Provide the required statement to complete the SqrRootUserInterface function. function sqrRoot = SqrRootUserInterface( ) usrNum = input('Enter a positive number: '); ; ________________________________________________________ fprintf('The square root of %f is %f\n', usrNum, sqrRoot); end function root = NewtonSquareRoot( x ) end

sqrRoot = NewtonSquareRoot( usrNum ) The variable sqrRoot must be assigned the value of calling NewtonSquareRoot with the argument userNum.

vector 1 norm

sum of the absolute values in an array

The cross product between two vectors produces a vector that lies in the same plane as the two vectors. that is perpendicular to the two vectors.

that is perpendicular to the two vectors. The cross product is also known as the vector product because the cross product produces a vector perpendicular to both vectors.

logistical indexing array: an error is generated if

the last true element in the logical indexing array specifies an array element that exceeds the number of elements in the indexed array

vector 2 norm

the square root of the sum of absolute values squared in an array

Given that dataTable is a 2 × 3 array, then dataTable([ false; true; false; true; false; true ]) returns a 6 × 1 column array. the transpose of the second row of dataTable. a 1 × 3 row array consisting of elements at indices (2,1), (2,2), and (2,3). a 1 × 3 column array consisting of elements at indices (2,1), (2,2), and (3,2).

the transpose of the second row of dataTable The logical indexing row array references the second, fourth, and sixth elements of dataTable, i.e. the entire second row, and returns it as a column array. This is equivalent to taking the transpose of the second row of dataTable.

persistent variable

to extend the scope of a variable beyond the limitations presented by the input list. In particular, it is sometimes useful to create a local variable in a function whose value persists after the function returns, rather than being cleared from memory after the function is executed. Such persistence is accomplished by declaring in the function a ___________ keyword being persistent

topMounts = [ 8848, 8611; % Asia (Everest, K2) 6962, 6893; % S. America (Aconcagua, Ojos del Salado) 6194, 5959 ] % N. America (McKinley, Logan) Write a relational expression that assigns the logical indexing array lowHeightsIdx the logical indices for all mountains with heights lower than 6900 m. lowHeightsIdx = (

topMounts < 6900 The indexing array is assigned logical values as a result of the relational operator. It will have true values at indices (2,2), (3,1), and (3,2) and false values everywhere else.

Gaussian elimination

transforms the linear system Ax=b with elementary row operations to an equivalent linear system Ux=c. The matrix U is a row-echelon matrix and reveals types of possible solutions with the coefficient matrix .A

Iterate as long as the user-entered number userNum is not -1.

while The iterations are not known before the loop, so use "while (userNum ~= -1)".

Iterate until the values of x and y are equal, where x and y are changed in the loop body.

while The iterations are not known before the loop, so use "while (x ~= y)".

Linear integer indexing: is the only way to access 2D array elements. will only return a scalar. will always return a 1D array.

will always return a 1D array. Each element accessed in the indexed array is returned in a row or column array by linear integer indexing.

Iterate while x is 99 or less. while (________) end

x <= 99

How many iterations are performed by the following loop (i.e., how many times is the loop body executed)?num = 2; while( num < 10 ) num = 2 * num; end

3 The loop body is executed once for num = 2 to set num to 4. The second iteration sets num to 8, the third sets num to 16, upon which the loop terminates.

Loop iterates 2 times. (Use the smallest possible integer value) i = 1; while ( i < 11 ) i = i +________ ; end

5 The loop will terminate after the second iteration when i is incremented to 11.

Indexing with a 2D logical array: can only be applied to 2D logical arrays. will always return a column array. generally returns a 2D array.

will always return a column array. The number of elements returned is equal to the number of true elements in the indexing array.

Linear indexing with a row array: will always return a row array. will always generate an error. can only index 2D integer arrays.

will always return a row array. The number of elements returned is equal to the number of elements in the indexing array.

Iterate while x is positive (including 0). while (____________) end

x >= 0

Given x, y, and z coordinates of the corner of a cube with one corner at the origin, calculate the cube volume. CalcCubeVol = @( _______________) x * y * z;

x, y, z

x = 0; while (x > 0) fprintf('%d ',x); x = x - 1; end fprintf('Bye');

Bye x=0 so loop is never entered.

local function or subfunctions

Functions defined after the first function can appear in the program file in any order after the main function. While the main function can be called from other programs and from the command line, ________________ can only be called by other functions defined within the same program file. cannot be called from outside the program file.

Loop iterates 2 times. i = 1; while ( i <=_______ ) i = i + 1; end

2 When i is 1 or 2, the expression "i <= 2" will evaluate to true.

topMounts = [ 8848, 8611; % Asia (Everest, K2) 6962, 6893; % S. America (Aconcagua, Ojos del Salado) 6194, 5959 ] % N. America (McKinley, Logan) Write an expression using integer array row-column indexing that returns the same result as the following expression: topMounts([ false, false; false, false; true, true ]) topMounts

(3,[1, 2])'or(3,1:2)'or(3,:)' The logical indexing array example given in the question retrieves the third row of the table. Using integer indexing to retrieve the third row returns a row array, which must then be transposed to create a column array.

How many iterations are performed by the following loop?num = 2; while( num > 10 ) num = 2 * num; end

0 The loop body is never executed since num is initialized to a value less than 10.

What is x after evaluating the following code? RaisedCos = @(angle) ( cosd(angle) )^2; x = RaisedCos(45);

0.5

Given the following while loop, what is the value assigned to variable z for the given values of variables a, b and c? mult = 0; while a < 10 mult = b * a if mult > c break; end a = a + 1 end z = a a = 1, b = 1, c = 0

1 z=1. In the first iteration, a and b will be 1. mult is assigned 1. Because 1 > 0, the if branch executes, so the

The loop iterates 10 times. i = 1; while ( i <= _____) i = i + 1; end

10 i is incremented to 11 at the end of the tenth iteration, and the expression "i <= 10" will evaluate to false.

Given the following code, how many times will the fprintf statement execute? i1 = 0; while (i1 < 3) i2 = 1; while (i2 <= 7) fprintf('%d%d ', i1, i2); i2 = i2 + 2; end i1 = i1 + 1; end

12 The outer loop will iterate 3 times for i1 = 0, 1, 2. While the inner loop will iterate 4 times, for i2 = 1, 3, 5, 7. Therefore 3 * 4 = 12. Be sure to pay careful attention to the conditional operators (in this case < versus the <=).

Assume user input for the GCD program results in numA = 18 and numB = 12. What is numB after the first and before the second iteration?

12 numB is < numA, so the else branch is taken leaving numB unchanged.

What is the output of the following code? i1 = 1; while (i1 < 19) i2 = 3; while (i2 <= 9) fprintf('%d%d ', i1, i2); i2 = i2 + 3; end i1 = i1 + 10; end

13 16 19 113 116 119 outer loop: i1 = 1, 11inner loop: i2 = 3, 6, 9i1 cannot exceed 19 so the outer loop only runs twice.i2 cannot exceed 9 so the inner loop will run 3 times.

Loop iterates 95 times. i = 1; while ( i <______ ) i = i + 1; end

96 i is incremented to 96 at the end of the last iteration, and the expression "i < 96" will evaluate to false.

Loop iterates from -100 to 31 (inclusive). i = -100; while ( i _____ 32 ) i = i + 1; end

< The while loop could also be "while ( i <= 31 )"

Complete the indexing statement such that only the entries in the second column of AnnuityTable are extracted, as indicated by the logical index array midIntrstIdx paymentSatCriteria =

AnnuityTable(midIntrstIdx, 2) The row indexing array is midIntrstIdx and the 2 indicates only the second column entries are of interest.

break statement

in a loop (either while loop or for loop) causes an immediate exit of the loop. Statements in the loop after the break statement do not execute. It can sometimes yield a loop that is easier to understand.

Given the rectangular coordinates a, b, and c of a point on the surface of a sphere centered at the origin given by x^2+y^2+z^2 =R^2, where R is the sphere radius, calculate the volume of the sphere. CalcRadius = @( a, b, c ) sqrt( a^2 + b^2 + c^2 ); CalcSphereVol = @( a, b, c ) (4/3) * pi * __________________________^3;

CalcRadius(a, b, c) An anonymous function can be called from within another anonymous function as long as it has been previously defined.

Write a statement that defines an anonymous function with the same name and input list, and which returns the same result as the following function definition: function f = CelToFah(c) f = (9 / 5) * c + 32; end

CelToFah = @(c) (9 / 5) * c + 32 The result of the @ operator is assigned to a variable with the desired name of the anonymous function. The input list is the same as the function definition. The result of the statement in the body of the anonymous function does not need to be assigned to an output variable.

continue statement

in a loop causes an immediate jump to the loop condition check. It can sometimes improve the readability of a loop.

Provide the required function call to the local function to complete the SineDegrees function. function x = SineDegrees( y ) x = sin (___________________); end function rad = DegsToRads( angle ) rad = ( pi/180 ) * angle; end

DegsToRads( y ) SineDegrees calls the local function DegsToRads to convert its input (assumed in degrees) to radians before calling the sin function. The functionality of SineDegrees is equivalent to the MATLAB function sind.

function dist = CalcDistLatLong( ) minsPerDeg = 60; secsPerMin = 60; secsPerDeg = minsPerDeg * secsPerMin; earthRadius = 6371; % Earth's radius in km function degOut = ConvertToDegrees( degIn, minIn, secIn ) end end ConvertToDegrees is a local function. True False

False ConvertToDegrees is a nested function, not a local function.

for index = 1:5 if index< 10 continue else disp(index) end end The loop will print at least some output. True False

False In each iteration, i is less than 10, so the continue statement executes.

Logical indexing must index all elements of an array. True False

False The last true logical indexing array element must specify an indexed array element within the indexed array size, but the logical indexing array may be bigger or smaller than the indexed array.

for index = 1:5 if index< 10 continue else disp(index) end end The loop will iterate only once. True False

False The loop will iterate 5 times. Continue jumps to the next iteration, thus preventing each iteration from printing anything. The continue statement doesn't break out of the loop though.

Integer indexing must index all elements of an array. True False

False Integer indexing specifies only the elements of the indexed array that are accessed.

How many iterations are performed by the following loop? num = -2; while( num < 10 ) num = 2 * num; end

IL (infinite loop) The loop is never terminated since num is initialized to a negative value (by definition less than positive 10) and becomes increasingly negative as each iteration is completed.

x = 10; while (x ~= 3) fprintf('%d ',x); x = x / 2; end

IL (infinite loop) because no matter how many times 10 is divided by 2, the result will never equal 3. The programmer perhaps should have used ">= 3".

An array that is being accessed by an indexing array.

indexed array

An array used to index another array.

indexing array

Any array of integers.

integer array

topMounts = [ 8848, 8611; % Asia (Everest, K2) 6962, 6893; % S. America (Aconcagua, Ojos del Salado) 6194, 5959 ] % N. America (McKinley, Logan) Write an expression that uses logical indexing to return the height of the second-tallest mountain per continent as a column array. topMounts(

[false, true; false, true; false, true] In the indexing array, all entries in the first column are false and all entries in the second column are true. A column array is returned.

logical indexing array

a special type of indexing array that consists of logical (i.e., true or false) values

A special type of integer array used for indexing.

integer indexing array

Write a statement that defines an anonymous function named absSin, which takes a single argument x in radians and returns the absolute value of the sine of x using MATLAB functions.

absSin = @(x) abs(sin(x)) The input list contains the single variable x. sin takes an argument in radians, and the result is then passed to abs to compute the absolute value of the sine of x.

Complete the logical expression to extract all the entries in the rows with interest rates less than 12% midIntrstIdx = (

interestRates < 12 ( interestRates < 12 ) creates a logical column array.

Row-column integer indexing uses two integer indexing arrays. True False

True The first integer indexing array specifies the row(s) of the accessed elements, while the second specifies the column(s).

Good practice is to ensure number of elements in the logical indexing array and the indexed array are equal. True False

True While the logical indexing array may be bigger or smaller than the indexed array, good practice is to ensure the logical indexing array and the indexed array are the same size.

function dist = CalcDistLatLong( ) minsPerDeg = 60; secsPerMin = 60; secsPerDeg = minsPerDeg * secsPerMin; earthRadius = 6371; % Earth's radius in km function degOut = ConvertToDegrees( degIn, minIn, secIn ) end end ConvertToDegrees can access the variable earthRadius without passing the variable as an argument. True False

True earthRadius is defined within the parent function of ConvertToDegrees and can be accessed by the nested function.

function dist = CalcDistLatLong( ) minsPerDeg = 60; secsPerMin = 60; secsPerDeg = minsPerDeg * secsPerMin; earthRadius = 6371; % Earth's radius in km function degOut = ConvertToDegrees( degIn, minIn, secIn ) end end At the command line, typing the statement angDeg = ConvertToDegrees(54,40,37) will result in an error. True False

True A nested function cannot be called directly from the command line.

function dist = CalcDistLatLong( ) minsPerDeg = 60; secsPerMin = 60; secsPerDeg = minsPerDeg * secsPerMin; earthRadius = 6371; % Earth's radius in km function degOut = ConvertToDegrees( degIn, minIn, secIn ) end end The statement angularDist = ConvertToDegrees(degIn1,minIn1,secIn1) - ConvertToDegrees(degIn2,minIn2,secIn2) can appear before the final end statement. True False

True Calls to nested functions can appear anywhere within the parent function.

Iterate with i from 1 to 100 (inclusive). for ____________________ end

i = 1:1:100

randInts = [ 20, 36, 3; 33, 2, 5; 9, 14, 42 ]. What value of primeIdx causes randInts(primeIdx) to return a column array of all the prime numbers in randInts using linear logical indexing? [false, false, false, false, true, false, true, true, false ] [ false; false; false; false; true; false; true; true; false ] [ false, false, true; false, true, true; false, false, false ] [ false; false; false; false; false; false; true; true; true ]

[ false; false; false; false; true; false; true; true; false ] The logical indexing column array references the fifth, seventh, and eighth elements of randInts, corresponding to numbers 2, 3, and 5, which are all the prime numbers in the original array.

Iterate with i from 212 to 32 (inclusive). for ______________ end

i = 212:-1:32

If aMat = [1, -1, 3; 2, 4, 5; 7, 11, 0] and aMat([ false, false, false, true, true, true, false, false, false]) aMat = [ 7 , 11 , 10 ] aMat = [ 2 ; 4 ; 5 ] aMat = [ -1 , 4 , 11 ] aMat = [ -1 ; 4 ; 11 ]

aMat= [-1,4,11] The logical indexing row array references the fourth through sixth elements of aMat, i.e. the entire second column, and returns a row array.

If aMat = [1, -1, 3; 2, 4, 5; 7, 11, 0] , bMat=aMat([ false,true, false; false, true, false; false, true, false]) bMat= [ 2 ; 4 ; 5 ] bMat= [ 2 , 4 , 5 ] bMat = [ -1 , 4 , 11 ] bMat = [ -1 ; 4 ; 11 ]

bMat=[-1;4;11] The row-column indexing extracts the second column and a column array is returned.

If aMat = [1, -1, 3; 2, 4, 5; 7, 11, 0] , bMat=aMat([ false, false, false; true, true, true; false, false, false]) bMat= [ 2 ; 4 ; 5 ] bMat= [ 2 , 4 , 5 ] bMat = [ -1 , 4 , 11 ] bMat = [ -1 ; 4 ; 11 ]

bMat=[2;4;5] The row-column indexing extracts the second row and a column array is returned.

iteration

each execution of the loop body

loops

execute a set of statements between the keywords that delimit the beginning and end

while loop

executes this list of statements (called the loop body) as long as the loop expression evaluates to true. The loop expression is a logical expression following the while keyword that evaluates to true or false. Logical expressions can include both relational operators (such as < or ==) and logical operators (such as &, |,or ~):

Logical indexing arrays typically result from

expressions that use relational or logical operators.

main function

first function

loop variable

variable is used to count the number of iterations


Ensembles d'études connexes

1.3 Physical and Chemical Properties

View Set

Effective Leading Citizens: Qualities of an Effective Leader

View Set

Marketing - NOT ALL ARE CORRECT, maybe 95%

View Set

Exam 5 Family - Quiz, Book, and PowerPoint questions (Ch 7, 8, 23, 24, 4, 5, 6)

View Set

The Outliers Study Guide Questions

View Set