Skip to main content
1-Visitor
January 18, 2013
Solved

Must be a scalar or a matrix

  • January 18, 2013
  • 2 replies
  • 29625 views

Hi all,

I am trying to add two range variables but I get the error "This value must be a scalar or a matrix". Please see the attachment.

Thanks

Best answer by StuartBruff

As Fred say, you can't add range variables. A range variable is an implied iterator - it provided the major form of iteration in the early versions of Mathcad before programming was added to provide the for loop.

A range variable is quite distinct from a vector. A vector is a one-column array in Mathcad whereas a range variable is a variable that holds a range, a specialized data type of the form "start,next..end". You can't perform arithmetic on this data type, hence you can't add them together. Whenever Mathcad encounters a range variable in an expression it automatically iterates over each of the values obtained by expanding the range. When Mathcad encounters a vector (or other array) it operates on the vector as a whole.

To allow me to make better use of range variables I created a general purpose function called vec that will convert a range variable into a vector - see attached worksheet for it application to your worksheet.

Stuart

2 replies

23-Emerald I
January 18, 2013

You can't add range variables. They work for plotting or for indices of vectors or matrices but they're not vectors so you can't operate on them.

23-Emerald V
January 19, 2013

As Fred say, you can't add range variables. A range variable is an implied iterator - it provided the major form of iteration in the early versions of Mathcad before programming was added to provide the for loop.

A range variable is quite distinct from a vector. A vector is a one-column array in Mathcad whereas a range variable is a variable that holds a range, a specialized data type of the form "start,next..end". You can't perform arithmetic on this data type, hence you can't add them together. Whenever Mathcad encounters a range variable in an expression it automatically iterates over each of the values obtained by expanding the range. When Mathcad encounters a vector (or other array) it operates on the vector as a whole.

To allow me to make better use of range variables I created a general purpose function called vec that will convert a range variable into a vector - see attached worksheet for it application to your worksheet.

Stuart