Root Solutions Blog

Mathcad can help if you’re stuck in the matrix

Posted by Angela Birlea on 22-Aug-2017 09:26:48

 

We’re not exactly talking about Blue Pills and Red Pills here, although I must admit, that would make an interesting subject. We will instead talk about matrices in Mathcad and hopefully you’ll learn a few tricks that will come in handy.

The terminology can be confusing when it comes to matrices, so let’s understand what these terms mean in the Mathcad world:

Array – a general term for a variable that can hold multiple values at indexed positions.

Vector – a 1D array that has multiple rows but only one column.

ORIGIN – a build-in variable that determines the index of the first element. By default is 0, but some people use 1 (and so have I, in the examples below).

math1-1.png

Matrix – a 2D array.

 math2-1.png

Confused yet? Let’s hope not!

Arrays are a type of variable, and operations can be performed on them, but there are some limitations you need to take into account. For example, multiplying two matrices in Mathcad is only possible if their sizes match, and you will get the “dot product” (bonus points if you remember this from algebra class).

math3-1.png

If this is not what you’re after, you have the option to bypass Mathcad’s way of dealing with matrix multiplication (or division), and vectorise the expression in order to perform element-by-element processing. This also means you can use vectors as arguments for functions that, in theory, only accept scalars. Happy days!

math5-1.png

I leave you with a list of pre-defined functions designed specifically for your array needs:

  • rows and cols – return the number of rows or columns in an array;
  • length – returns the number of elements in a vector;
  • last – returns the index of the last element in a vector; the number returned depends on the value of ORIGIN.
  • max and min – return the max or min element in an array;
  • stack – places the arrays on top of each other, merging them into one;
  • augment – places the arrays side-by-side, merging them into one.

For more information on PTC Mathcad, PTC Mathcad Products and Mathcad training - why not visit our online Mathcad Store. - Click Here!

Topics: Mathcad

Subscribe to Email Updates for Product News & Offers.