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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Range Variables in User Defined Functions

astevenson-2
1-Newbie

Range Variables in User Defined Functions

I'm using MathCAD 15 in Windows 7 environment. I'm trying to create a vector using a range variable or at least that's what I think I'm doing. I thought I could set up a similar command sequence in user defined function as below:

Capture.JPG

But as you can see in my user defined function, MathCAD is not happy with me or range variables don't work the same way in a user defined function as they do in the regular environment.

Capture.JPG

1 ACCEPTED SOLUTION

Accepted Solutions

StuartBruff wrote:

Andy Stevenson wrote:

I'm using MathCAD 15 in Windows 7 environment. I'm trying to create a vector using a range variable or at least that's what I think I'm doing. I thought I could set up a similar command sequence in user defined function as below:

But as you can see in my user defined function, MathCAD is not happy with me or range variables don't work the same way in a user defined function as they do in the regular environment.

Just to emphasize the point Luc is making, you cannot use range variables inside a loop in the way you want (and as seems reasonable).  You have to use a for or while loop instead.   You can still define a range variable to use, either inside a program or externally, but you have to handle them differently.

Oops, pressed a button too soon.  I forgot to add an example of the normal use of a for loop and a non-looping recursive method.

Stuart

View solution in original post

6 REPLIES 6
LucMeekes
23-Emerald III
(To:astevenson-2)

First off, the default start index for a vector is set by ORIGIN, which normally is 0. Apparently you've set it to 1 otherwise junk[0 would have been shown.

To create a vector in a program do:

This one is independent of the value of ORIGIN.

Success!
Luc

Andy Stevenson wrote:

I'm using MathCAD 15 in Windows 7 environment. I'm trying to create a vector using a range variable or at least that's what I think I'm doing. I thought I could set up a similar command sequence in user defined function as below:

Capture.JPG

But as you can see in my user defined function, MathCAD is not happy with me or range variables don't work the same way in a user defined function as they do in the regular environment.

Capture.JPG

Just to emphasize the point Luc is making, you cannot use range variables inside a loop in the way you want (and as seems reasonable).  You have to use a for or while loop instead.   You can still define a range variable to use, either inside a program or externally, but you have to handle them differently.

Stuart

StuartBruff wrote:

Andy Stevenson wrote:

I'm using MathCAD 15 in Windows 7 environment. I'm trying to create a vector using a range variable or at least that's what I think I'm doing. I thought I could set up a similar command sequence in user defined function as below:

But as you can see in my user defined function, MathCAD is not happy with me or range variables don't work the same way in a user defined function as they do in the regular environment.

Just to emphasize the point Luc is making, you cannot use range variables inside a loop in the way you want (and as seems reasonable).  You have to use a for or while loop instead.   You can still define a range variable to use, either inside a program or externally, but you have to handle them differently.

Oops, pressed a button too soon.  I forgot to add an example of the normal use of a for loop and a non-looping recursive method.

Stuart

Thanks Guys. I knew had to get around it with just writing a brute force "for loop" in my user defined function. Just found it odd that the range variable method doesn't work inside a user defined function.

LucMeekes
23-Emerald III
(To:StuartBruff)

Stuart, your implementation isn't ORIGIN-proof...

{apart from the fact that Andy wanted steps of 0.1}

Luc

StuartBruff
23-Emerald II
(To:LucMeekes)

LucMeekes wrote:

Stuart, your implementation isn't ORIGIN-proof...

{apart from the fact that Andy wanted steps of 0.1}

Luc

Hi Luc,

Sorry,  I want trying to make it origin-independent,  just address the differences between range variable calypso inside and outside of a program.  For that purpose,  the scaling factor could have been anything.

Cheers,

Stuart

Top Tags