(How to use the interactive programs in this tutorial)

By Kardi Teknomo, PhD.
LinearAlgebra

<Next | Previous | Index>

Matrix Size Validation

In this page, I will explain how you will input and validate the size of a matrix or a vector in the interactive programs of this Linear Algebra tutorial.

First, your input must be numbers (real or integer), or a sequence of numbers (not string of words or other characters) separated by commas, or space or semicolon.

  • Use period to separate decimal part from the whole number.
  • Comma or space is used to separate numbers in a row. Comma does not represent a thousand.
  • Semicolon is used to separate rows

Example:

  • you should write 1112.25 and not 1,112.25
  • You should not write 1112,25 as a number because the program will interpret it as two numbers of 1112 and 25.

As an alternative form, you may also use space to replace comma.


Example:
1 2  3, 4       5

It is equivalent to
1, 2, 3, 4, 5;

When you input the sequence of numbers above, you will get
vector example

A vector or a matrix will have several rows. When you want to write a sequence of numbers on different rows, use semi colon to separate each rows. The last row’s semicolon is optional.  A matrix or a vector is defined by its size that is the number of rows and the number of columns. We always write matrix size as number of rows first and then the number of columns.

A vector is always a column vector (with only one column). Thus, instead of comma, you need to use semicolon to separate each entry.


Example:
30; 45; 60

It will produce

example column vector

When you want to write a row vector (consists only one row), you separate the numbers by commas.


Example:
30, 45, 60


It will produce

example row vector

A matrix may have several rows and several columns. You can write a matrix or a vector as sequence of numbers, separated by commas in a row and semicolon to mark the end of each row. Optionally, you can also write it in a nice format using carriage return.

Example:
30, 30, 60; 45, 30, 60; 30, 45, 15; 60, 180, 120;

It is equivalent to
30, 30, 60;
45, 30, 60;
30, 45, 15;
60, 180, 120;

Both of them will produce

example matrix

A matrix must have equal number of entries for all rows. If you mistype the entries, the program will accept it not as a matrix and the matrix or vector operations on your input will produce error or wrong answer. That is why you need to validate your input in the interactive program below.

Example:
1,  , 3; 4, 5, 6; , 8
It will produce
example wrong input


It shows that the first row has 2 entries, the second row has 3 entries and the third row has 1 entry.  Empty space between commas is not considered as an entry. Since the numbers of entries in each row are not equal, the matrix size cannot be determined.

Report in rational format

Some of the interactive programs in this linear algebra tutorial may have options to show the output as approximate fractional format. If you click the random example button, you may obtain a number in with several decimal digits. If you checkreport in rational format , the result will be in fraction. To separate the whole number from the fraction, the program is using under bar.


Example:
-2.25, 100.33333, 0.5, -51.125;

It will produce

Example vector in rational format

Now you are ready to play around with this exciting linear algebra tutorial, you may use the Next and Previous Navigation or go directly from the left navigation bar, or you can go back to the index of this tutorial.

<Next | Previous | Index>

Rate this tutorial or give your comments about this tutorial

This tutorial is copyrighted.

Preferable reference for this tutorial is

Teknomo, Kardi (2011) Linear Algebra tutorial. https:\\people.revoledu.com\kardi\tutorial\LinearAlgebra\