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

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

Issue: Range behaviour

DM_10127316
12-Amethyst

Issue: Range behaviour

Hi,

 

*** I attached a Mathcad sheet exemplifying the issue***

 

I have a variable j defined below:

DM_10127316_1-1706869724615.png

This variable can take values like [1], [2], etc. except when type is 12, in which case j=[0,1,2,...,11]

My idea is that the user can select an individual type or select type=12, which includes all types from 0 to 11..

When I multiply two vectors using j to access their elements, it works as intended:

DM_10127316_2-1706870029768.png      DM_10127316_3-1706870052139.png

 

The problem occurs when I want to store this result in a variable.

 

DM_10127316_4-1706870241889.png

 

I want to get rid of those zeros and mimic the C_j * M1_j results shown above. I tried to create a another variable i but for some reason it gives an error:

DM_10127316_5-1706870548742.png

 

I wonder if there is a cleaner/easier way of doing this?

 

Regards,

 

 

 

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:DM_10127316)

I see no need for any variable "j" - neither as a range, nor as a vector.

You may use the if-function:

Werner_E_0-1706987052348.png

Note that you need to apply vectorization when calculating C*M1.

 

If you need the variable T to be a vector/matrix even though it consists of just one value, you can do it that way:

Werner_E_1-1706987164823.png

 

and of course you don't have to use the if-function, you can also use the programmed if-statement

Werner_E_2-1706987220787.png

 

Prime 9 worksheet attached

View solution in original post

3 REPLIES 3
LucMeekes
23-Emerald III
(To:DM_10127316)

With the statement:

LucMeekes_1-1706871628122.png

you are simply multiplying two array elements (which are scalars in your case) for every value of j.

If j is a single value, you get a single value as result. If j is a range, you get a range of results:

one result for each product of C[j and M1[j.

With the assignment:

LucMeekes_2-1706872576924.pngyou are creating array elements for each value in the range of j. If j is a single value, say 3, the array T gets created with 4 elements, one with index 0, the second with index 1, third with index 2 and fourth with index 3 (because j=3). The first three are created by default, and set to 0. (You have ORIGIN=0, so indexing starts at 0, another common setting for ORIGIN is 1, so indexing starts at 1 and with the same value j=3 you would get for T a 3-element vector, the first 2 being 0 and the third containing the product C[3*M1[3.

Hope this sheds some light.

You could solve it by:

LucMeekes_3-1706873221573.png

LucMeekes_4-1706873240686.png

Success!
Luc

 

 

ttokoro
20-Turquoise
(To:DM_10127316)

image.pngimage.pngimage.pngimage.pngimage.png

Werner_E
25-Diamond I
(To:DM_10127316)

I see no need for any variable "j" - neither as a range, nor as a vector.

You may use the if-function:

Werner_E_0-1706987052348.png

Note that you need to apply vectorization when calculating C*M1.

 

If you need the variable T to be a vector/matrix even though it consists of just one value, you can do it that way:

Werner_E_1-1706987164823.png

 

and of course you don't have to use the if-function, you can also use the programmed if-statement

Werner_E_2-1706987220787.png

 

Prime 9 worksheet attached

Announcements

Top Tags