cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

## how to stack a range variable  8-Gravel

## how to stack a range variable

hi, i just started using mathcad. can anyone tell me the mistake i am doing here and how to stack the x[i and y[i into one column matrix. i am using mathcad 15.

Thank you 1 ACCEPTED SOLUTION

Accepted Solutions  23-Emerald III
(To:rizz12)

You can only stack vectors or matrices.

A range variable is NOT a vector (or matrix), it is sort of an iteration operator. You cannot stack range variables.

You can use a range variable to create vectors and matrices, or use them as an index to their elements.

Further use of range variables is in for statements in a mathcad program, and for supplying the independent variable in a plot. I guess that's about it.

In short: you must create vectors, if you want to stack.

Your case: x and y are vectors, and you properly used range variables to create them.

If you want to stack them to create a new vector W just state:

W:= stack(x,y)

Success!
Luc

The index of the first element of a vector (or row or column of a matrix) is ORIGIN. It's default value is 0, but it can be set to any value (within limits). The most common other value is 1. You can type ORIGIN= to see that (in your case) it's value (is 0).

To display a vector, such as x, instead of x[i= you'd normally just type

x=

With the statement W[i := stack(x[i,y[i) you've instrcuted mathcad to create a new vector W element by element (the iteration operator). The first element (at index 0, so W[0  ) consists of the stacking of x[0 and y[0.

Stacking x[0 and y[0 gives a two element vector (x[0 on top of y[0). The second element of w, that is w[1 becomes a 2-element vector likewise.

When you evaluate W[i, you get this funny display that says each element of W is a vector, 2 rows and 1 column; that is, a 'nested array'.

You can double-click the result and set display properties. Choose 'expand nested arrays' to show its full beauty...

4 REPLIES 4  23-Emerald III
(To:rizz12)

You can only stack vectors or matrices.

A range variable is NOT a vector (or matrix), it is sort of an iteration operator. You cannot stack range variables.

You can use a range variable to create vectors and matrices, or use them as an index to their elements.

Further use of range variables is in for statements in a mathcad program, and for supplying the independent variable in a plot. I guess that's about it.

In short: you must create vectors, if you want to stack.

Your case: x and y are vectors, and you properly used range variables to create them.

If you want to stack them to create a new vector W just state:

W:= stack(x,y)

Success!
Luc

The index of the first element of a vector (or row or column of a matrix) is ORIGIN. It's default value is 0, but it can be set to any value (within limits). The most common other value is 1. You can type ORIGIN= to see that (in your case) it's value (is 0).

To display a vector, such as x, instead of x[i= you'd normally just type

x=

With the statement W[i := stack(x[i,y[i) you've instrcuted mathcad to create a new vector W element by element (the iteration operator). The first element (at index 0, so W[0  ) consists of the stacking of x[0 and y[0.

Stacking x[0 and y[0 gives a two element vector (x[0 on top of y[0). The second element of w, that is w[1 becomes a 2-element vector likewise.

When you evaluate W[i, you get this funny display that says each element of W is a vector, 2 rows and 1 column; that is, a 'nested array'.

You can double-click the result and set display properties. Choose 'expand nested arrays' to show its full beauty...  8-Gravel
(To:LucMeekes)

Thank you so much. it worked.  23-Emerald I
(To:rizz12)

First off, you're not stacking range variables.  You have one properly defined range variable, " i ", which you're using as an index to create two vectors " x ", and " y ".  Then you use the same range variable to create " W ",  where W[i := stack(x[i,y[i).  This creates a vector of arrays, one element of x is stacked with one element of y to create a two-row, single column array which is one element of W.

The proper command would be W := stack(x,y), which puts the two vectors properly stacked.  8-Gravel
(To:Fred_Kohlhepp)

thank you 