

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























This comprehensive 150-question exam bank is designed to prepare candidates for CEE 20 Introduction to Computational Engineering Problem Solving Using MATLAB Homework 1-6 Complete Solutions 100% Completed Updated 2026/2027.. Every question is aligned with the latest official content outline and includes a detailed, evidence-based rationale, an explanation of why each remaining option is incorrect, and a supporting reference.
CEE 20 Introduction to Computational Engineering Problem Solving Using MATLAB Homework 1-6 Complete Solutions 100% Completed Updated 2026/2027., exam bank, practice questions, verified answers, detailed rationales, test prep, study guide, review questions, certification exam, latest update, CEE 20 Introduction to Computational Engineering Problem Solving Using MATLAB Homework 1-6 Complete Solutions 100% Completed Updated 2026/2027., exam bank, practice questions, verified answers, detailed rationales
A) The least-squares solution via QR factorization. B) The exact solution using LU with partial pivoting. C) An error because A is not square. D) The element-wise division [0.2 0.4; 0.5 0.667].
' C o r r e c t A n s w e r : B Rationale: For a square, nonsingular matrix, the backslash operator (mldivide) solves Ax=b using LU factorization with partial pivoting, not QR (which is for overdetermined systems) or element-wise division (./). The system is square, so no error occurs.
A) Persistent variables are cleared when the function clears. B) Global variables must be declared in every function that uses them. C) Persistent variables retain values between calls but are cleared by clear all. D) Local variables are visible in the base workspace.
' C o r r e c t A n s w e r : C Rationale: Persistent variables retain their values across function calls but are cleared by clear all (or clear functions). Global variables require declaration in each function, but B is not the best answer because it omits that they also must be declared in the base workspace; C is unambiguously true. Local variables are not visible in the base workspace.
C) transpose(A) D) reshape(A,3,1)
' C o r r e c t A n s w e r : D Rationale: reshape(A,3,1) explicitly reshapes the 1×3 row into a 3×1 column. A' is the complex conjugate transpose; for real A it equals A.', but A.' is non-conjugate transpose. transpose(A) is equivalent to A.'; all yield a column for real A, but only D is guaranteed to produce a column without relying on transpose semantics. However, for real A, A' also yields [1;2;3]. The question asks which yields the column vector; A, B, C, and D all do for real A. The intended unique answer is D because it directly reshapes; but A' also works. This question is ambiguous; discard.
A) [1 1.3 1.6 1.9] B) [1 1.3 1.6 1.9 2.2] C) [1 1.3 1.6 1.9 2] D) [1 1.3 1.6 1.9 2.0]
' C o r r e c t A n s w e r : A Rationale: The colon operator generates values from 1 to 2 with step 0.3: 1, 1.3, 1.6, 1.9; the next value 2. exceeds 2, so it is excluded. Floating-point representation may show 1.9 as 1.9 but not include 2.0. Options B and C include values beyond or equal to 2 incorrectly; D includes 2.0 which is not generated because 1.9+0.3=2.2>2.
A) readtable('data.csv') B) csvread('data.csv') C) importdata('data.csv') D) load('data.csv')
' C o r r e c t A n s w e r : A Rationale: readtable automatically detects headers and returns a table, the recommended modern approach. csvread is deprecated and does not handle headers; importdata returns a struct; load does not parse CSV with headers into a table.
A) legend('sin(x)') B) legend(sin(x)) C) legend('sin(x)','Location','best') D) legend('sin(x)','AutoUpdate','off')
' C o r r e c t A n s w e r : C Rationale: legend('sin(x)','Location','best') adds a legend with label and specifies location, a valid modern syntax. legend('sin(x)') also works but does not specify location; however, the question asks for correct addition, and both A and C are valid. The intended unique answer is C because it includes location, but A is also correct. This question is ambiguous; discard.
A) && and || always evaluate both operands. B) & and | short-circuit for scalar operands. C) && and || short-circuit and require scalar logical operands. D) && and || work element-wise on arrays.
Rationale: MATLAB has no built-in divmod; quorem operates on symbolic polynomials, and mod returns only one output. The standard idiom is floor for the quotient and rem for the remainder.
A) y = zeros(size(x)); B) y = zeros(length(x), 1); C) y = zeros(numel(x)); D) y = zeros(1, length(x));
' C o r r e c t A n s w e r : A Rationale: size(x) returns the exact dimension vector, preserving orientation for row or column inputs. The other choices force a column, a square matrix, or a row, which can silently reshape results.
A) Assignment always copies the full array immediately. B) Passing an array to a function always copies it. C) Modifying a shared array triggers a copy only then. D) Arrays are passed by reference and never copied.
' C o r r e c t A n s w e r : C Rationale: MATLAB uses copy-on-write: assignment and argument passing create shared references, and a physical copy occurs only when one variable is modified. Immediate copying, unconditional function copies, and never-copying are all false.
A) load('data.csv') B) readmatrix('data.csv') C) csvread('data.csv') D) readtable('data.csv')
' C o r r e c t A n s w e r : D Rationale: readtable detects headers and preserves mixed variable types in a table. load and csvread are legacy numeric-only readers, and readmatrix discards the header and forces numeric output.
A) plot(t, y, 'o') B) plot(t, y, '-') C) bar(t, y) D) stem(t, y)
' C o r r e c t A n s w e r : B Rationale: A solid line connects samples, approximating the continuous sinusoid. Marker-only, bar, and stem styles emphasize discrete samples and misrepresent the smooth signal.
A) Newton's method with analytic derivative B) Fixed-point iteration with g(x)=x C) Bisection with a tighter bracket D) Regula falsi without modification
' C o r r e c t A n s w e r : A
Rationale: Newton's method is quadratically convergent near a simple root, so it usually needs far fewer iterations than bisection or regula falsi. The trivial fixed-point map g(x)=x does not converge to the root.
A) rank(A) == 2 B) cond(A) < 1 C) rcond(A) < eps D) det(A) > 0
' C o r r e c t A n s w e r : C Rationale: rcond returns an estimate of the reciprocal condition number; a value below eps signals numerical singularity. The matrix has rank 1, infinite condition number, and zero determinant, so the other statements are false.
A) diff(xexp(x)) B) int(xexp(x), x) C) taylor(xexp(x)) D) limit(xexp(x), x, 0)
' C o r r e c t A n s w e r : B Rationale: int performs symbolic integration, returning exp(x)*(x-1). diff differentiates, taylor expands in a series, and limit evaluates a point limit-none produce the antiderivative.
A) catch err; disp(err.message); end B) try ... catch ... finally ... end C) if errorflag; cleanup; end D) onCleanup inside the try block
' C o r r e c t A n s w e r : B Rationale: The finally block runs regardless of whether an error occurred, guaranteeing cleanup. Catch-only blocks skip cleanup on success, conditional flags are unreliable, and onCleanup objects require proper scope handling.
A) [1 64; 2187 65536] B) [5 64; 2187 65536] C) [1 64; 2187 65536] but with element-wise multiplication instead D) Error: matrix dimensions must agree
' C o r r e c t A n s w e r : A Rationale: The .^ operator performs element-wise exponentiation: A(1,1)^B(1,1)=1^5=1, A(1,2)^B(1,2)=2^6=64, A(2,1)^B(2,1)=3^7=2187, A(2,2)^B(2,2)=4^8=65536. Option B incorrectly uses 5^1=5 for the first element. Option C misinterprets the operator. Option D is wrong because dimensions agree.
A) nargin B) nargout C) nargchk D) inputname
' C o r r e c t A n s w e r : B Rationale: nargout returns the number of output arguments with which the function was called. nargin returns the number of input arguments. nargchk validates the number of input arguments (now replaced by narginchk).
Rationale: i n t ( f , x ) c o m p u t e s t h e i n d e f i n i t e i n t e g r a l o f f w i t h r e s p e c t t o x : "+ ( x ^ 2 MATLAB does not include the constant of integration. Option B is the derivative. Option C includes '+ C' which MATLAB does not add. Option D is the original function.
A) A becomes [1 2 3] B) A becomes [4 5 6] C) A becomes a 2x2 matrix D) Error: cannot delete rows
' C o r r e c t A n s w e r : A Rationale: The assignment A(2,:) = [] deletes the second row, leaving only the first row [1 2 3]. Option B would be if the first row were deleted. Option C is incorrect because only one row remains. Option D is false; rows can be deleted.
A) It is cleared when the function is cleared from memory B) It retains its value between function calls C) It is shared across all functions D) It is initialized only once per session
' C o r r e c t A n s w e r : B Rationale: persistent variables retain their values between calls to the function in which they are declared. They are cleared when the function is cleared (clear functionname) or when MATLAB exits. They are not shared across functions (that would be global). Option D is not precise; they are initialized once when the function is first called, but that is not the best description.
A) 3 4 2 B) 3 4 C) 24 D) 2
' C o r r e c t A n s w e r : A Rationale: zeros(3,4,2) creates a 3-by-4-by-2 array. size returns a vector containing the length of each dimension: [3 4 2]. Option B would be for a 2-D array. Option C is the total number of elements. Option D is the number of dimensions.
A) Throws an index-out-of-bounds error because end+1 exceeds the array size. B) Appends the value 5, extending A to length 4 with no warning. C) Replaces the last element of A with 5 and leaves length unchanged. D) Creates a new column vector by concatenating 5 vertically.
' C o r r e c t A n s w e r : B Rationale: In MATLAB, indexing with end+1 beyond the current length automatically grows the array, so A(end+1)=5 appends 5 and A becomes length 4. It does not error, does not overwrite the last element, and does not change orientation.
A) The colon operator always produces single-precision values. B) sum uses pairwise summation that changes the mathematical result.
C) 0.1 is not exactly representable in binary floating point, so accumulated rounding occurs. D) MATLAB rounds sum to 15 significant digits, discarding the exact value.
' C o r r e c t A n s w e r : C Rationale: The decimal 0.1 has no finite binary representation, so each element carries a tiny representation error that accumulates during summation. Colon does not force single precision, sum's pairwise algorithm is accurate but not exact for inexact inputs, and MATLAB does not round sum's output to 15 digits.
A) [m,i] = f(v); B) f[v] = m; C) function f(v) = m; D) m,i = f(v);
' C o r r e c t A n s w e r : A Rationale: Multiple outputs are requested with square brackets on the left: [m,i] = f(v). The other forms are not valid MATLAB assignment syntax for function calls.
A) while ~feof(fid), line = fgetl(fid); disp(line); end B) for k=1:inf, line = fgets(fid); end C) line = fread(fid); while ischar(line), line = fgetl(fid); end D) while fid > 0, line = fscanf(fid); end
' C o r r e c t A n s w e r : A Rationale: The standard idiom tests ~feof(fid) and uses fgetl to read a line without the newline character. The other loops either misuse fgets/fread/fscanf or have invalid termination conditions.
A) loglog(x,y) B) semilogx(x,y) C) semilogy(x,y) D) plot(x,y,'Log')
' C o r r e c t A n s w e r : C Rationale: semilogy sets the y-axis to logarithmic scale and leaves x linear. loglog makes both axes logarithmic, semilogx makes only x logarithmic, and plot does not accept 'Log' as a scale option.
A) roots([1 0 -2 -5]) B) fzero(@(x) x.^3-2x-5, 2) C) fsolve(@(x) x^3-2x-5, 2) D) interp1([1 2 3],[ -6 -1 16],2)
' C o r r e c t A n s w e r : B Rationale: fzero is designed for a scalar nonlinear equation and accepts an initial guess, making it the direct choice. roots finds polynomial roots but returns all roots, fsolve is for systems, and interp1 only interpolates tabulated data.
A) 1/ B) 0. C) x^3/ D) 3*x^
' C o r r e c t A n s w e r : B Rationale: The colon operator (e.g., 1:5) creates a vector of values from start to end with step 1, commonly used in for loops. It is not limited to indexing (A), not a comment (C), and not multiplication (D).
A) linspace(0,1,10) B) logspace(0,1,10) C) 0:0.1: D) zeros(1,10)
' C o r r e c t A n s w e r : A Rationale: linspace(0,1,10) generates 10 linearly spaced points from 0 to 1. logspace creates logarithmically spaced points (B), 0:0.1:1 yields 11 points (C), and zeros creates an array of zeros (D).
A) High B) Low C) Error D) Nothing
' C o r r e c t A n s w e r : A Rationale: Since x=5 > 3, the condition is true, so 'High' is displayed. Options B, C, D are incorrect because the condition is satisfied and syntax is valid.
A) x = 0:0.1:2pi; plot(x, sin(x)) B) plot(sin(0:0.1:2pi)) C) fplot(sin, [0, 2*pi]) D) All of the above
' C o r r e c t A n s w e r : D Rationale: A l l t h r e e a p p r o a c h e s c o r r e c t l y p l o t s i n ( x ) o v e r [ 0 , 2 À ] : A u s e s e x p l i c i t directly, and C uses fplot with a function handle. Thus D is correct.
A) Bisection B) Newton-Raphson C) Secant D) False position
' C o r r e c t A n s w e r : B Rationale: Newton-Raphson uses f'(x) to iteratively approach the root. Bisection and false position use bracketing, and secant approximates the derivative without evaluating it.
A) Element-wise division B) Solves the linear system using matrix factorization C) Computes the inverse of A D) Performs left division for scalars only
' C o r r e c t A n s w e r : B Rationale: The backslash operator solves linear systems efficiently using LU or QR factorization, not by explicitly computing the inverse. It is not element-wise (A) and works for matrices (D).
A) fprintf B) csvread C) load D) textscan
' C o r r e c t A n s w e r : C Rationale: The load function reads numeric data from ASCII files into a matrix. fprintf writes (A), csvread is for CSV files (B), and textscan requires a file identifier and format (D).
A) To define a function B) To handle errors gracefully C) To create a loop D) To plot data
' C o r r e c t A n s w e r : B Rationale: try-catch allows execution of code that might error, catching exceptions to prevent program termination. It does not define functions (A), create loops (C), or plot (D).
A) [1 64; 2187 65536] B) [5 12; 21 32] C) [1 36; 9 64] D) [5 64; 2187 32]
' C o r r e c t A n s w e r : A Rationale: The .^ operator performs element-wise exponentiation: A(i,j)^B(i,j). Thus 1^5=1, 2^6=64, 3^7=2187, 4^8=65536. Option B is element-wise multiplication, C is squaring each element, and D mixes operations.
A) roots([2 -4 3 -1]) B) roots([-1 3 -4 2]) C) roots([2 4 3 1]) D) roots([2 -4 3])
' C o r r e c t A n s w e r : A Rationale: The roots function expects a coefficient vector in descending powers of x: [2 -4 3 -1]. Option B reverses order, C has wrong signs, and D omits the constant term.
A) A row vector with 11 elements from 0 to 1 in steps of 0. B) A column vector with 10 elements from 0 to 1 C) A row vector with 10 elements from 0 to 0. D) An error because the step size is not integer
' C o r r e c t A n s w e r : A Rationale: The colon operator creates a row vector from start to end inclusive with the specified step. 0:0.1:1 yields 11 elements (0,0.1,...,1.0). It is a row vector, not column, and no error occurs.
A) Scripts can accept input arguments, functions cannot
A) load('data.txt') B) readmatrix('data.txt') C) importdata('data.txt') D) All of the above can read numeric data
' C o r r e c t A n s w e r : D Rationale: load, readmatrix, and importdata can all read numeric data from a text file, though readmatrix is recommended in modern MATLAB. Thus all are valid, making D the best answer.
A) To define a function with multiple outputs B) To handle errors gracefully without stopping execution C) To optimize code performance by preallocating arrays D) To create a loop that runs until a condition is met
' C o r r e c t A n s w e r : B Rationale: try-catch allows execution of code that might error; if an error occurs in the try block, control passes to the catch block, enabling graceful error handling. It is not for function definition, optimization, or loops.
A) A 1×3 row vector [2 3 4] B) A 3×1 column vector [2;3;4] C) The scalar 24 D) A 1×2 row vector [2 12]
' C o r r e c t A n s w e r : A Rationale: zeros(2,3,4) creates a 3-D array; size returns a row vector with one element per dimension, so [2 3 4] is correct. The scalar 24 is numel, and the other shapes misrepresent the dimension count.
A) [0 0; 0 0] B) [2 4; 6 8] C) [4 6; 10 12] D) [2 4; 6 8]
' C o r r e c t A n s w e r : C Rationale: Matrix power A^2 = [7 10; 15 22]; element-wise square A.^2 = [1 4; 9 16]; difference is [6 6; 6 6]? Wait-recompute: A^2 = [11+23, 12+24; 31+43, 32+44] = [7 10; 15 22]. A.^2 = [1 4; 9 16]. Difference = [ 6; 6 6]. None listed. Let me correct: A^2 = [7 10; 15 22]; A.^2=[1 4; 9 16]; diff=[6 6; 6 6]. This is not among options. I must fix the question. Use A=[1 2;3 4], compute A^2 - A.^2 = [6 6;6 6]. Not in options. Change to A=[ 2;3 4], A^2 - 2*A.^2? That gives [5 2; -3 -10]. Not helpful. Instead ask: what is A^2? Options [7 10;15 22] correct. But question asks difference. I'll replace with a known correct: For A=[1 2;3 4], what is A^2? Options: A [7 10; 22] correct; B [1 4;9 16]; C [3 6;9 12]; D [4 6;10 12]. That's fine. I'll set question accordingly.
A) Reverses the order of rows while preserving column order B) Reverses the order of columns while preserving row order C) Extracts the last row and replicates it D) Sorts each column in descending order
' C o r r e c t A n s w e r : A Rationale: The index vector end:-1:1 selects rows from last to first, reversing row order; the colon preserves all columns. It does not reverse columns (B), replicate a row (C), or sort values (D).
A) Passing a large array to a function always copies it immediately B) Modifying an input inside a function never affects the caller's variable C) MATLAB may share data until a write occurs, then copies D) Input arguments are passed by reference and changes propagate
' C o r r e c t A n s w e r : C Rationale: MATLAB uses copy-on-write: arrays are shared until modified, at which point a copy is made, so caller data is protected (B, D false). A copy is not made eagerly on pass (A false).
A) Rely on MATLAB's automatic loop timeout B) Add an iteration counter with a maximum-iteration break C) Convert it to a for loop with a fixed large count D) Use try/catch to catch infinite-loop errors
' C o r r e c t A n s w e r : B Rationale: MATLAB has no automatic infinite-loop timeout (A false), and try/catch cannot catch a non-terminating loop (D false). A guarded counter with break ensures termination; converting arbitrarily (C) may still be unbounded.
A) subplot(2,3,1) only B) tiledlayout(2,3); nexttile C) tiledlayout(2,3); nexttile([1 1]) D) tiledlayout(2,3); nexttile(1)
' C o r r e c t A n s w e r : B Rationale: tiledlayout(2,3) followed by nexttile without arguments creates and returns handles for each tile as needed; subplot(2,3,1) creates one axes only (A). nexttile([1 1]) and nexttile(1) target a single tile, not all (C, D).
A) 2. B) 2. C) 2. D) 2.
' C o r r e c t A n s w e r : C Rationale: f ( 2 ) =" 1 , f ' ( x ) = 3 x ²" 2 s o f ' ( 2 ) = 1 0 ; x 1 = 2" (" 1 ) / 1 0 = 2. 1. W a i t : 2" (" 0. 1 ) = 2. 1 closest listed to the true root 2.0946 is C when iterating; x1=2.1 (not listed). Among options, 2.0946 is the converged root. (Answer C.)
A) polyfit(x, log(y), 1) then exponentiate coefficients B) polyfit(x, y, 2) and use quadratic coefficients C) interp1(x, y, 'spline') at original points D) fitlm(x, y) with default linear terms
' C o r r e c t A n s w e r : A Rationale: Log-linearization yields a linear least-squares problem: log y = log a + b x, so polyfit(x, log y,1) recovers b and log a. Quadratic fit (B) and linear fitlm (D) impose wrong model forms; spline interpolation (C) does not estimate parameters.
Rationale: numel returns the total number of elements in any array, including cell arrays. length returns the largest dimension, size(C,1) returns only rows, and ndims returns the number of dimensions (2), not element count.
A) [3 4; 1 2] B) [1 2; 3 4] C) [2 1; 4 3] D) [4 3; 2 1]
' C o r r e c t A n s w e r : A Rationale: The row index end:-1:1 reverses row order while the colon keeps all columns, yielding [3 4; 1 2]. B is unchanged, C reverses columns, and D is a full 180-degree rotation.
A) assignin('base','x',x) B) global x C) evalin('caller','x') D) persistent x
' C o r r e c t A n s w e r : A Rationale: assignin('base','x',x) writes x into the base workspace. global declares shared scope but does not create a base variable, evalin reads from a workspace, and persistent retains value between calls within the function only.
A) Compare with a tolerance instead of exact equality B) Use single precision for the counter C) Increment by a non-integer step D) Add a break statement in every iteration
' C o r r e c t A n s w e r : A Rationale: Floating-point accumulation error can make exact equality never true, so tolerance-based comparison is robust. Single precision worsens error, non-integer steps increase error, and unconditional break defeats the loop's purpose.
A) f = @(x,y) x.^2 + y; B) f = inline('x^2+y'); C) f = function(x,y) x^2+y; D) f = @x @y x^2+y;
' C o r r e c t A n s w e r : A Rationale: The @(x,y) syntax defines an anonymous function with two inputs. inline is deprecated, 'function' is invalid outside a function file, and chained @ creates nested function handles, not a two-argument function.
A) hold on B) figure C) clf
D) newplot
' C o r r e c t A n s w e r : A Rationale: hold on retains the current axes contents so subsequent plotting commands overlay. figure opens a new window, clf clears the figure, and newplot resets the axes, all erasing prior content.
A) 2. B) 1. C) 2. D) 3.
' C o r r e c t A n s w e r : A Rationale: The cubic x^3-2x-5 has a real root near 2.0946 within the bracket [2 3], where the function changes sign. The other values are not roots of this polynomial.
A) readmatrix('data.csv') B) csvread('data.csv') C) dlmread('data.csv') D) textscan(fopen('data.csv'))
' C o r r e c t A n s w e r : A Rationale: readmatrix is the recommended, optimized function for numeric CSV data. csvread and dlmread are not recommended, and textscan requires a file identifier and format specification.
A) x = A\b B) x = inv(A)b C) x = b/A D) x = A^-1b
' C o r r e c t A n s w e r : A Rationale: The backslash operator uses efficient, stable matrix division. inv(A)b and A^-1b explicitly invert (less accurate, slower), and b/A solves a different right-division system.
A) 4 B) 5 C) 3 D) Error, since endpoint is not exactly reached
' C o r r e c t A n s w e r : A Rationale: The colon operator uses a computed tolerance; floating-point accumulation yields elements 1.0, 1.1, 1.2, 1.3 (the last within tolerance), so numel is 4. B assumes inclusive rounding up, C ignores the endpoint, and D is false-no error is raised.
A) A(3) B) A(2) C) A(2,1) only; linear indexing cannot access it D) A(1,2)
Rationale: The backslash operator uses LU with pivoting (or QR for rectangular), which is more stable than explicit inverse. A is discouraged due to error amplification. C solves a different system. D may be used for rank-deficient cases but is not generally the most stable for square ill-conditioned systems.
A) 2 B) 3 C) true D) Error: sum of logical not allowed
' C o r r e c t A n s w e r : A Rationale: y is logical [0 1 1]; sum converts to double and returns 2. B counts all elements, C is not numeric sum, D is false-sum works on logicals.
A) It overwrites the file by default B) It appends by default C) It requires a file identifier D) It cannot write numeric matrices
' C o r r e c t A n s w e r : A Rationale: writematrix overwrites by default; use WriteMode='append' to append. B is false. C is false-writematrix takes a filename. D is false-it writes numeric matrices.
A) v.^ B) v^ C) v.*v^ D) power(v,2) only
' C o r r e c t A n s w e r : A Rationale: The element-wise power operator .^ squares each element. B attempts matrix power (invalid for non-square). C is incorrect syntax/logic. D is valid but not the only correct form; A is the canonical vectorized expression.
A) [1 3 2 4] B) [1 2 3 4] C) [1 2; 3 4] D) [1; 2; 3; 4]
' C o r r e c t A n s w e r : B Rationale: A(:) linearizes A in column-major order to [1;3;2;4]; transposing yields [1 3 2 4], not [1 2 3 4]. Option B mistakenly assumes row-major linearization, which MATLAB does not use. Option A is the correct column-major result, and option C is the original matrix.
A) u * v' B) u .* v C) u' * v D) sum(u * v)
' C o r r e c t A n s w e r : A Rationale: uv' performs a 1-by-n times n-by-1 matrix product, yielding the scalar sum of elementwise products. u.v returns an elementwise vector, u'v is an outer product matrix, and sum(uv) is invalid because u*v is a dimension mismatch.
A) Returns empty y = [] B) Returns y = 0 C) Runtime error: output argument 'y' not assigned D) Returns the last computed value
' C o r r e c t A n s w e r : C Rationale: MATLAB raises an error when a requested output argument is never assigned on any executed path. It does not default y to empty, zero, or the last intermediate value. This is a common source of runtime errors in student functions.
A) y = 0; B) y = zeros(1, numel(x)); C) y = []; D) y = NaN;
' C o r r e c t A n s w e r : B Rationale: Preallocating y with zeros of the final size prevents MATLAB from reallocating and copying the array each iteration. Starting with a scalar or empty array forces growth, which is slower for large loops. NaN scalar also grows dynamically.
A) linspace(0, 2pi, 50) B) 0:2pi/50:2pi C) logspace(0, 2pi, 50) D) 0:(2pi)/49:2pi
' C o r r e c t A n s w e r : A Rationale: linspace(a,b,n) returns exactly n points including both endpoints. The colon form 0:2pi/50:2pi yields 51 points, and dividing by 49 is incorrect for inclusive spacing. logspace produces logarithmically spaced points, not linear.
A) Elementwise addition requires equal size or scalar B) x.^2 is invalid for matrices C) y.^2 transposes y automatically D) The plus operator performs matrix multiplication
' C o r r e c t A n s w e r : A Rationale: Elementwise addition requires operands of the same size (or one scalar); 3×2 plus 2×3 is a dimension mismatch. The .^ operator is valid elementwise, does not transpose, and + is never matrix multiplication.
A) save('data.mat','a','b') B) save data.mat a b -ascii C) save('data.mat')