GETTING STARTED
Defining Vectors and Matrices
Mathcad has many powerful features and functions for dealing with arrays of numbers, such as vectors and matrices. Creating a vector or matrix in Mathcad involves just choosing the dimensions of the array and filling in the placeholders.
For example, to create a vector
like the one shown below, click to position the red crosshair in some free space and
• Type v:
• Press [Ctrl] m or choose Matrix from the Insert menu.
•
Fill
in the appropriate number of rows and columns. For example, the vector below
has
rows and
column.
• Click on Insert or OK.
• Fill in the placeholders with the appropriate values. Use [Tab] to move from placeholder to placeholder inside the vector, or click on the appropriate placeholder to select it.
To access a particular element of a vector, you use the subscript operator, which you create by typing a left square bracket ( [ ), or by using the
button in the Calculator toolbar.
By default the first element has the index
:
Type
See on screen
v[0=
The next element has the index
:
Type
See on screen
v[1=
The last element has the index
, and so on:
Type
See on screen
v[2=
For convenience, you can define the index as a range variable to access all of the elements at once:
Type
See on screen
i:0;2
v[i=
Practice
Set a matrix with 1 column and 4 rows.
Set the index as a range, then check your result.
It’s important to understand that an index for a vector will always be a range of consecutive integers in Mathcad, starting from 0.. Any values not specifically defined by you will be defined to equal 0 by Mathcad. For example, consider:
Type
See on screen
i:2;5
wrong[i:1
wrong=
You might expect the vector wrong to have four elements (the 2nd, 3rd, 4th and 5th). However, as you can see, it has six. This is because internally, Mathcad still keeps track of the 0th and 1st elements. And because these were not specifically defined, Mathcad made them equal to 0.
It is helpful to use vector elements as arguments of functions.
For example, we’ll use the variables and function defined below:
Now define a vector and use its elements as an argument of the function:
Try defining a vector and using its elements in a function off to the right.
You can also use vectors as arguments of functions. For example:
Type
See on screen
f(x):[Ctrl]4x
Here we use the vector summation operator, which is also available via the
button on the Vector and Matrix toolbar.
Most of the vector and matrix operators can be found in the Vector and Matrix toolbar, but below is a listing of a few basics:
Operation
Keystroke
Button
Display
Dot product
[Shift]8
Displays like scalar multiplication.
Cross product
[Ctrl]8
Determinant
|
Column
[Ctrl]6
Returns the 2nd column of
.
Mathcad has a wide variety of built-in functions for manipulating vectors and matrices. Here is a small sampling, using the matrix
defined below:
Purpose
Example
Number of columns
Number of rows
Largest value in matrix
Eigenvalues of a matrix