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

The community will undergo maintenance on October 16th at 10:00 PM PDT and will be unavailable for up to one hour.

Calculation with range variables using units

Sergey
14-Alexandrite

Calculation with range variables using units

Hello.

 

I created a range variable "y" with units (see attached file). Then I try to calculate parameter "H". Mathcad says that "This value must be scalar or a vector". I think it is strange that the calculation fails. 

What do I do wrong here?

 

Sergey

ACCEPTED SOLUTION

Accepted Solutions

Hi

It was possible in Prime 9 to define a range variable and use an undocumented trick to turn it into a vector.  The trick was to use a display equal sign after range definition.

In Prime 10 the undocumented trick no longer works you must create the vector.

There is a variable H and a function H(y) they should be different names.

Capture.JPG

 

View solution in original post

4 REPLIES 4

Hi

It was possible in Prime 9 to define a range variable and use an undocumented trick to turn it into a vector.  The trick was to use a display equal sign after range definition.

In Prime 10 the undocumented trick no longer works you must create the vector.

There is a variable H and a function H(y) they should be different names.

Capture.JPG

 

Sergey
14-Alexandrite
(To:terryhendicott)

Thank you.

 

So both methods works all the same?

I prefer function definition to creation of the vector.

 

Also, why are you using the subscript "i" while calculating "y"? Shouldn't it be the same as to write y= instead yi= ?

 

Sergey

Hi,

The i is not a subscript but an index into a vector.  The way to see the difference is to place the cursor on them.  If a little square bracket appears it is an index not a subscript.  To get the square bracket index you type y[i  where y is the variable, a left hand square bracket, and i is the index from 0 to 30. 

Capture.JPG

I probably confused you by using the index i in the display equal for y.  

Capture3.JPGDoes the same asCapture2.JPG

Cheers

Terry

 

Werner_E
25-Diamond I
(To:Sergey)


@Sergey wrote:

Hello.

 

I created a range variable "y" with units (see attached file). Then I try to calculate parameter "H". Mathcad says that "This value must be scalar or a vector". I think it is strange that the calculation fails. 

What do I do wrong here?

You confused a range with a vector, thats the problem.

As Terry already wrote what you did would work OK in versions of Prime (and also Mathcad) prior to Prime 10 because there the inline evaluation of the range automatically turned it into a vector. This undocumented (and sure not intuitive) trick was turned off with version 10 by PTC, which IMHO is OK, but I would have hoped that they would at the same time provide a 'legal' and more intuitive alternative to turn a range into a vector, but PTC didn't.

So you either have to create a vector like Terry had suggested or you use the following utility function which turns a range into a vector.
Remark: This function has its flaws as it won't work OK when used in a program!

Werner_E_0-1722545036803.png

The vectorizations I applied aren't mandatory in case of the type of function you are using (as Prime automatically applies implicit vectorization), but you will see the necessity if you replace the expression y^2 by the equivalent y*y .

Werner_E_1-1722545226342.png

So my advice is  not to rely on automatic implicit vectorization but rather always explicitly apply vectorization when you want it to be done.

 

Prime 10 sheet attached

 

Announcements

Top Tags