Math 171 - Alexiades
Lab 3
On Arrays (vectors and matrices)

(always read the entire Lab before you start working on it)

A. Learn more Matlab
  a. Review Basics: Bkbn Chap.3
  b. Work through Bkbn § 4.1 - 4.4 and 5.1 - 5.4
  c. and Downey: § 4.5 - 4.8

B. Work to do  
  In (the Command Window of) Matlab, figure out how to do the following, using appropriate Matlab operations:
    (first on paper, then try each on Matlab)
  (a) Create a 3x3 magic matrix and call it A.   Extract the a23 entry of A and write it to a23.
  (b) Extract the 2nd row of A and write it to a vector r2.   Extract the 3rd entry of r2, write it to r23.
  (c) Extract the 3rd column of A and write it to a vector c3.
  (d) Try r2+c3. Does it work ? It should not! makes no math sense! but Matlab produces some 3x3 matrix. Ignore!
    Find b=r2'+c3   (note the ', for transpose) which does make sense.
  (e) Solve the linear system   Ax = b. This is very easy in Matlab:   x = A \ b
    Think of it as   x = A inverse times b, which would be the case when A is invertible: x = A−1 b.
    It is the magic of Matlab that   A \ b   gives something meaningful even for non-square matrices!
  (f) Check if this x is indeed a solution by computing:   y = A*x−b .   Is it ?
  (g) Generate an array x of numbers between a=0 and b=10, equispaced every dx=0.5 . Suppress the output of x = ... .
    Find the size (length) of the array x. Into how many subintervals has [a, b] been subdivided?
  (h) To generate N+1 equispaced numbers in the interval [a, b], what should dx be?
  (i) Generate same array as in (g) using linspace, call it xx , suppressing printing. What should its 3rd element be? Extract it from xx to verify.

C. Prepare the file Lab3.txt   for submission:
  1. Turn on diary ( >> diary Lab3.txt )
  2. Insert (as comment lines): Your Name, Lab3, Date
  3. Do each part (a)-(i) carefully   (the less junk you create, the less you will have to clean up...).
    Label each part as in the Lab: (a), (b), ...
    Insert separators: %================================== between parts.
    Do not forget to insert an answer to each question.
  4. Close the diary:   ( >> diary off )
  5. Using a PLAIN TEXT editor, edit the file Lab3.txt to clean it up,
   leaving only the correct version of
what is asked for in each part.
   All matlab commads you entered, and their result, should be shown.

D. Submit it on Canvas before the due date.