**This is an old revision of the document!** ----
====== Math 445 mid-term exam with solutions ====== **1.** Write one line of Matlab code that returns the 4th column of the matrix $A$. A(:,4) **2.** Write Matlab code that sets all entries in the 3rd row of the matrix $A$ to zero. Its possible to do this in one line, but you can use several. A(3,:) = 0; or A(3,:) = zeros(1,size(A,2)); or [M,N] = size(A); A(3,:) = zeros(1,N); **3.** Write one line of Matlab code for an anonymous function that computes the value of the polynomial $3x^2 - 2x - 7$ for an input argument $x$. f = @(x) 3*x^2 - 2*x - 7; **4.** How would you use Matlab and the anonymous function from problem 3 to find a numerical solution to the equation $3x^2 - 2x - 7 = 0$? One line of code should do it. x = newtonsearch(f,2); or x = fzero(f,2); Note: 2 is an initial guess for the solution, chosen because f(2) = 1 (this is relatively close to zero). **5.** Write one line of Matlab code that evaluates to 1 (true) if $x$ is negative and $y$ is positive, and 0 (false) otherwise. x < 0 && y > 0 **6.** Write one line of Matlab code that evaluates to 1 (true) if both $x$ and $y$ are positive or if both are negative, and 0 (false) otherwise. (x < 0 && y < 0) || (x > 0 && y > 0) **7.** Write one line of Matlab code that counts how many components of the vector $v$ are exactly zero. sum(v==0) **8.** Show how to solve the system of equations with three lines of Matlab code. <latex> \begin{align*} 3x + y + 2z - 6 &= 0 \\ 9z - x - 8 &= 0 \\ 5y - 4x - 1 &= 0 \end{align*} </latex>