Lab 4
Operations and Built-in Functions

CS211 Lab Policy:

Instructions:

  1. Create a small MATLAB program named lab4a that gets from the user the coordinates of two points on the Cartesian plane and then computes and displays the distance between them.  After creating your program, test it with several pairs of points.  Make sure one test case reverses the order of the the points entered in another test case.  For example, test your program with both of the following cases:
     
    1. (x1, y1) = (1,1) and (x2, y2) = (2,2)
       
    2. (x1, y1) = (2, 2) and (x2, y2) = (1, 1).

    Your program should include a standard comment header block and comments as appropriate.  Your program should perform the following steps:

    1. Clear the screen and tell the user what the program will do.
       
    2. Prompt for and get from the user the x and y coordinates of the two points.
       
    3. Compute the distance between the two points - take the difference between the two x values and the two y values, square both values, add them up, and take the square root (using the built-in function sqrt).
       
    4. Display the distance between the two points.
       
  2. Create a small MATLAB program named lab4b that solves a system of equations.  Refer to the lesson notes for an algorithm to accomplish this. After creating your program, test it with different size systems of equations.  Your program should include a standard comment header and comments as appropriate.  Your program should perform the following steps:
  1. Clear the screen and tell the user what the program does
     

  2. Prompt for and get a matrix that contains the coefficients of the equations. (Use a single input statement and ask the user to type in brackets and use semicolons appropriately to define a square matrix.)
     

  3. Prompt for and get a column vector that defines the right-hand side of the system of equations. (Use a single input statement.)
     

  4. Solve for the unknowns
     

  5. Display the values calculated for the unknowns. (Use disp for output so that you can display an entire array with a single command.)
     

  6. Use your solution values and prove that they are correct. (Recalculate the right-hand side values -- did you get the original values?)
     

  7. Display your re-calculated right-hand side values to prove that the system was solved correctly. (Use disp for output.)

Turn-in:

Submit your lab4a.m and lab4b.m files.