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

Range Variables in User Defined Functions

SOLVED
astevenson-2
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

Re: Range Variables in User Defined Functions

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

Re: Range Variables in User Defined Functions

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

Re: Range Variables in User Defined Functions

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

Re: Range Variables in User Defined Functions

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

Re: Range Variables in User Defined Functions

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.

Re: Range Variables in User Defined Functions

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

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

Luc

Re: Range Variables in User Defined Functions

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

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."