next home previous intro. problems contents

12.1 Solution to Introduction to Matrices Problems

    1.   matrix B

    2.   B^T matrix

    3. No. One reason is that BBT. Another reason is that B is not square.
      Note: Only one of the reasons is necessary.

    1. matrices are easy

    2. friends

    3. calculator

    4. The answers will vary.

    1.   matrix
      Note: On all solutions of this type (including this and the next 2 problems), rows could be switched and/or columns may be switched. The only requirement is that each of these numbers lines up with both of its labels.
      Therefore, matrix is also an appropriate solution.

    2.  matrix
      Note: Make sure that this matrix corresponds to the solution that the student gave on part (a) if the columns or rows were not as we ordered them in part (a).

    1.  matrix

    2.  matrix
      Please refer to the notes on the previous problem.

    1.  matrix

    2.  matrix
      Please refer to the notes on problem 4.


Computer Program

We have written sample programs in QBasic and Pascal. These programs are not meant to be examples of perfect programming style, but they do work. The goal of the programming assignments is to help students express what they have learned about matrices. Programming makes students think about each step of a problem.

Qbasic:

 
REM This program asks for a matrix to be input.

REM It prints the matrix and its transpose.

REM This program uses no commands that are specific to matrices.

CLS

PRINT “This program prints your matrix and its transpose.”

INPUT “Enter the dimensions of the matrix separated by a comma.”,m,n

DIM a(m,n)

PRINT

PRINT “Please press enter after each element of the matrix. ”

PRINT “Enter all the elements of one row before the next row. ”



REM This loop reads the matrix

FOR i=1 to m

   FOR j=1 to n

      INPUT a(i,j)

   NEXT j

NEXT i



REM This loop prints the matrix

PRINT

PRINT “This is the matrix that you entered: ”

FOR i=1 to m

   FOR j=1 to n

      PRINT a(i,j),

   NEXT j

   PRINT

NEXT i



REM This loop prints the transpose of the matrix

PRINT

PRINT “This is the transpose of your matrix: ”

FOR j=1 to n

   FOR i=1 to m

      PRINT a(i,j),

   NEXT i

   PRINT

NEXT j

END




Pascal:


Program intro(input, output);

{This program asks for a matrix to be input.

 It prints the matrix and its transpose.

 This program uses no commands that are specific to matrices.}



uses crt; {Necessary for some Pascal compilers}



type

   matrix=array[1..10,1..10] of real;



var

   m,n: integer; {dimensions of the matrices}

   a: matrix;  {matrix}



procedure readmatrix(var a:matrix; m,n:integer);

   var 

      i,j: integer; {counters}



   begin {read}

   for i:=1 to m do

      begin {do}

      for j:=1 to n do 

         read(a[i,j]);

         readln;

      end; {do}

   end; {read}



procedure writematrix(a:matrix; m,n:integer);

   var 

      i,j: integer; {counters} 



   begin {write}

   for i:=1 to m do

      begin {each line}

      writeln;

      for j:=1 to n do 

         write(a[i,j]:6:2);

      end; {each line}

   writeln;

   end; {write}



procedure writetranspose(a:matrix; m,n:integer);

   var 

      i,j: integer; {counters}



   begin {write}

   for j:=1 to n do

      begin {each line}

      writeln;

      for i:=1 to m do 

         write(a[i,j]:6:2);

      end; {each line}

   writeln;

   end; {write}



begin{main program}

   clrscr;

   writeln('Enter the dimensions of the matrix ');

   writeln('separated by a space. Then hit return.');

   read(m,n);

   writeln('Enter your matrix.');

   writeln('Enter each element followed by a return.');

   writeln('Enter the first row before you go to the next row.');

   readmatrix(a,m,n);

   writeln('The matrix that you entered is :');

   writematrix(a,m,n);

   writeln('The transpose of your matrix is :');

   writetranspose(a,m,n);

   writeln('Press return to leave the program');

   readln;

end. {main program}

next home previous go to the top intro. problems contents

Send comments on material to Tamara Carter

These pages are maintained by Hilena Vargas (hvargas@rice.edu)
Updated: September 21, 2000

 Copyright ©1995 - 2000 Tamara Lynn Anthony