Skip to main content
1-Visitor
February 18, 2015
Solved

Set variable array to add number

  • February 18, 2015
  • 2 replies
  • 1703 views

In the attached Mathcad Prime worksheet I am attempting to create variables L sub 1 through 4 where each value of L start at 5ft and adds a distance to it based on it's array value of L. This seems trivial, what am I missing in the attached?

Best answer by Werner_E

Don't use inline evaluation after defining the range variable i. Delete the = after definition and if you want to see what you have created, use i=... in a separate region.

Using the inline eval as you did converts the range i into a vector and you can't use vector elements to index another vector L. Its an undocumented dirty trick to quickly turn a range into a vector.

2 replies

Werner_E25-Diamond IAnswer
25-Diamond I
February 18, 2015

Don't use inline evaluation after defining the range variable i. Delete the = after definition and if you want to see what you have created, use i=... in a separate region.

Using the inline eval as you did converts the range i into a vector and you can't use vector elements to index another vector L. Its an undocumented dirty trick to quickly turn a range into a vector.

dsochor1-VisitorAuthor
1-Visitor
February 19, 2015

Thank You Werner, is there a way to turn a vector back into a range variable (not that I have an example where I would want to do this, just curious).

25-Diamond I
February 19, 2015

Daniel Sochor wrote:

Thank You Werner, is there a way to turn a vector back into a range variable (not that I have an example where I would want to do this, just curious).

No and this would not make much sense as the values of a range are equally spaced while the elements of a vector could be anything you like. So conversion would have to fail most of the times.

But it sure is very easy to write a very small function to convert a vector to a range by just using the first, second and last element of that vector:

It sure is a design error that ranges and vectors look perfectly alike in Prime. This can be very confusing,