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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Translate the entire conversation x

Range variables and conversion to other formats (Mathcad Prime 10)

Geoff_UK
3-Newcomer

Range variables and conversion to other formats (Mathcad Prime 10)

Hi, I am a new user of Mathcad Prime 10, with some experience of Mathcad but all gained long ago, before Prime came along. I have set up some functions to operate on range variables with equispaced input values. I want to work with the resulting range variables but have hit problems, partly due to a general lack of understanding and maybe partly due to the known limitation of Prime 10 

https://www.ptc.com/en/support/article/CS416474 -- corrected link

 

I can plot the output vs the input on an XY plot and the values check out correctly.

 

To export the resulting XY table to Excel, I tried to use https://community.ptc.com/t5/Mathcad/MathCad-Prime-9-0-Exporting-data-set-Excel/td-p/913932

The input/independent range variable is recognised and entered into the Excel cell. The output/dependent range variable is not recognised.

 

I have also tried various "range to vector" conversions but these all seem to have the limitation of only working on the input/independent range variable. I need a method that works on non-equally spaced values.

Converting range variables to vectors. - PTC Community

matrix - Trying to change a range variable to an array in mathcad prime v10 - Stack Overflow

 

IsScalar reports that both the input and output variables are columns of scalars. rows reports that the input variable has 0 rows. I'm not sure how to interpret this information.

 

I chose range variables because they seemed intuitive to use, but that approach seems to have created problems. I would be grateful for any advice, even if that is to go back and reconstruct my worksheet using a different approach. 

11 REPLIES 11
StuartBruff
23-Emerald IV
(To:Geoff_UK)

As you have discovered, range variables may seem intuitive, but they are the root cause of many of the problems people encounter using Mathcad.

 

First off, a range variable is a variable that contains a range.

 

A range is a specific data type that holds two or three elements that specify a sequence of values: the first element of the range's expansion, the upper limit of the range, and (optionally) the second value in the expansion.

 

When it occurs on the left-hand side of a definition (≔ or ≡) or evaluation (=) operator, a range tells Mathcad to iterate over the implied sequence.

 

Think of a range as an implied for loop.

 

Any of the range-to-vector functions you've seen should work with what I interpret to be your problem.  Once you have converted σt to a vector, you simply apply εt to it (vectorizing as needed).

 

I've only got Mathcad Express, so you'll probably want to substitute a programmed version of vec for the vec` function I've used.

 

2025 10 07 B.png

 

Stuart

Hi Stuart,

Thank you for taking the time to reply. It's late in the day here and I'll need to come back to this problem tomorrow. I was setting up an example worksheet as you replied, so I will add in your code to that and upload it tomorrow.

Werner_E
25-Diamond I
(To:Geoff_UK)

The support article CS41647 you linked to has nothing to with Prime!??

 

The thread concerning exporting data to Excel suggests a solution which worked up to Prime 9 but was broken in Prime 10 and above on purpose.

Following a range definition with a numeric evaluation (=) converted the range into a vector. This does not work in Prime 10 and above. In Prime 10 you have to use one of the range2vec function posted in various thread. Starting with Prime 11 you can use the new built-in "vec" function to do the job.

 

Its not perfectly clear what you are trying to achieve and what exactly you mean when you constantly talk about "input" and "output".

Actually I don't understand why you don't provide concrete examples and a worksheet, stating wat exactly you expect Prime to do for you.

 

My crystal ball thinks it has an idea and could imagine that they simply apply a function to a range variable and label the result “Output.”
But range variables are not made for that!
Range variables should only be used as abscissa values in 2D plots, for indexing vectors and matrices, and for loops (“for” in programs or sum or product), and for nothing else!

 

You may define a range variable x and feed it into a function like sin(x). You sure will see a collection of sine values and you can use sin(x) at the ordinate of a 2D plot.

But what you see is neither a range nor a vector. Its kind of an invalid object.

You may already have noticed that you can't even assign it a variable nor are able to access individual elements.

Werner_E_2-1759871427605.png

 

Solution is to define x as a vector, not as a range or convert the range x into a vector x using a function like "vec".

Now you can feed this vector x as argument in your function. You should use vectorization (the arrow over the expression) even though sometimes (like in the simple example in the pic) its not necessary. The result is a vector and it can be assigned a value or individual values can be accessed.  Of you can export these vectors to external files or use them in a plot.

Werner_E_3-1759871466276.png

 

EDIT: Oh, Stuart's reply wasn't visible yet when I started mine, but as we all know, two heads are better than one...

Geoff_UK
3-Newcomer
(To:Werner_E)

Hi Werner

Thanks for your reply. I edited my original post to fix the link. Sorry for the confusion.

I will need to reply properly tomorrow. I will add your solutions to my test worksheet.

StuartBruff
23-Emerald IV
(To:Geoff_UK)


@Geoff_UK wrote:

I can plot the output vs the input on an XY plot and the values check out correctly. 


Yes, the range variable will work on the plot as you have used it.  See my notes about what a range variable is in my previous message.

 

Mathcad effectively sees a Plot as an evaluation.  So, when Mathcad sees a range variable in a Plot, it iterates over the range's implied sequence of values.  

 


@Geoff_UK wrote:

To export the resulting XY table to Excel, I tried to use https://community.ptc.com/t5/Mathcad/MathCad-Prime-9-0-Exporting-data-set-Excel/td-p/913932

The input/independent range variable is recognised and entered into the Excel cell.


In Werner's worksheet, he's used the pre Mathcad Prime 10 undocumented feature of letting the evaluation operator convert a range variable dependent definition operator result into a vector.

 

As you are aware, that trick no longer works in Mathcad Prime 10 (or 11), necessitating the use of a range-to-vector conversion function.  

 

Presuming you've used such a function, what you pasted into Excel was not a range variable but a vector.

 

A vector is a very different beast from a range variable.  It can hold all of the values of a sequence rather than just a "description" of the values in the sequence.

 


@Geoff_UK wrote:

... The output/dependent range variable is not recognised. 


No, as Werner pointed out, evaluating εtt) doesn't result in a Mathcad data type.  It is effectively just a printed list of the result of separately evaluating εtt) for each value of σt. That's it.  See my previous message for getting a vector of these values.

 


@Geoff_UK wrote:

..,I have also tried various "range to vector" conversions but these all seem to have the limitation of only working on the input/independent range variable. I need a method that works on non-equally spaced values.


Again, see my previous message for getting a vector of the functions output.

 

All a range variable does is describe a simple, linear sequence. 

 

There is no method (as of yet) for directly converting the result of evaluating a function over a range variable - there isn't an intrinsic Mathcad iterator type that describes or holds such values.

 

If you look at (one of) the internal representations of the ranges and vector,

 

2025 10 07 C.png

 

you should see something like:

 

Simple Range Variable: k≔1…5

(:= (@LABEL VARIABLE k) (@RANGE 1 5))

 

Stepped Range Variable: x≔0,0.1…1

(:= (@LABEL VARIABLE x) (@STEPRANGE 0 0.1 1))

 

Vector:  v≔0,0.1…1

(:= (@LABEL VARIABLE v) (@MATRIX 5 1 1 2 3 4 5))

 

Hopefully, this might help further show the differences between a vector and a range variable as data types.

 


@Geoff_UK wrote:

IsScalar reports that both the input and output variables are columns of scalars. rows reports that the input variable has 0 rows. I'm not sure how to interpret this information. 


This is the result of Mathcad iterating over a range variable.  For each (implied) value in the range's sequence, Mathcad evaluates IsScalar(value), and value is a scalar.  Similarly, rows(value) will result in 0 for each value (as a scalar has no rows).

 

Recall what I said about the output of such evaluations effectively being a printed list of these values, and not a data type in its own right.  

 


@Geoff_UK wrote:

I chose range variables because they seemed intuitive to use, but that approach seems to have created problems. I would be grateful for any advice, even if that is to go back and reconstruct my worksheet using a different approach. 


I mentioned range variables not being as intuitive to use as one might think.  Primarily, I infer from posts such as yours, people aren't really aware of the fundamental difference between a range variable and a vector.

 

I hope the above has been of some use in explaining why you've had the problems you have.

 

There have been various user proposals mooted by users over the years to do away with range variables and have Mathcad stand in their stead, with Mathcad iterating over them where appropriate.  These proposals have never gained traction, despite range variables being the cause of many such problems as you describe..

 

Stuart

There are various other methods of skinning your particular cat.

 

2025 10 07 D.png

 

Have you considered upgrading to Mathcad Prime 11?  I'm not aware of many (if any) downsides to doing so, and you get the built-in vec and IsRange functions (albeit, vec is incomplete as it does not flatten matrices, unlike the recommended MP10 workaround).

 

Stuart

Thank you both for taking the time to share these suggestions. I have attached a file showing what I tried to achieve and my efforts so far to fix it so far. I can now export the table of input and output values into Excel. That unblocks progress on my wider problem at work. Within Mathcad, I still have some work ahead to understanding exactly what you are telling me. I have vacation coming up so it will be some time before I can post here again.

 

Knowing that my variable "out" was not a defined Mathcad data type now makes it easier to understand why there is no particular help/support available for this situation.

 

Data into Excel SB 01.mcdx seems to be incompatible with Mathcad 10. I will enquire about the company moving to version 11.

 

 

StuartBruff
23-Emerald IV
(To:Geoff_UK)

Try the attached Mathcad Express 10 worksheet, Geoff.

Werner_E
25-Diamond I
(To:Geoff_UK)

Since you apparently had difficulty implementing my suggestion, I hope that the attached file will be of assistance.

 

Prime 10 sheet attached

Hi @Geoff_UK,

 

I wanted to see if you got the help you needed.

If so, please mark the appropriate reply as the Accepted Solution. It will help other members who may have the same question.
Of course, if you have more to share on your issue, please pursue the conversation. 

 

Thanks,  
Anurag

Hi, Can we keep the discussion open please, because I need to review the latest contributions following return from vacation and give suitable feedback to the responses that have been provided.

Announcements

Top Tags