Skip to main content
April 19, 2010
Question

Range variables in local definition

  • April 19, 2010
  • 3 replies
  • 11678 views
Range variables can be used to assign multiple vector or matrix values. For example:
M[i := i^2
A[i := B[j,i+1

However, the same construct does not work with a local definition--in a function definition, for example.
M[i <- i^2

Is this behavior expected? Do I really need to use a for loop to reproduce the behavior for local definitions inside a function? Or is it a bug? I consider it a bug since there is no apparent reason this shouldn't work. I should be able to do the same thing inside a function that I do in the main worksheet.

I'm using Mathcad 14.0 M030.

3 replies

1-Visitor
April 19, 2010
>> Do I really need to use a for loop to reproduce the behavior for local definitions inside a function?<<

Yep. Local variables are never range variables, even if their value is a range. And a global range variable cannot be used in a function definition, due to the restriction that if a range variable appears on the right of an assignment (:=) it must also appear on the left.
__________________
� � � � Tom Gutman
1-Visitor
April 20, 2010
On 4/19/2010 10:27:18 PM, cperk wrote:
>Range variables can be used to
>assign multiple vector or
>matrix values. For example:
> M[i := i^2
> A[i := B[j,i+1
>
>However, the same construct
>does not work with a local
>definition--in a function
>definition, for example.
> M[i <- i^2
>
>Is this behavior expected? Do
>I really need to use a for
>loop to reproduce the behavior
>for local definitions inside a
>function? Or is it a bug? I
>consider it a bug since there
>is no apparent reason this
>shouldn't work. I should be
>able to do the same thing
>inside a function that I do in
>the main worksheet.
>
>I'm using Mathcad 14.0 M030.

A range variable isn't a 'vector' as would happen in MatLab. It is one of the confusions.

Also, for no particular reason, a for loop is required in programmes (i.e. when using <- ). It is a design choice.

Philip Oakley
April 21, 2010
On 4/20/2010 6:21:40 AM, philipoakley wrote:
>A range variable isn't a 'vector' as
>would happen in MatLab. It is one of the
>confusions.

Thank you. I understand the difference. Even
though they are not the same, it is common
practice to access and assign vector and matrix
values using a range variable in the subscripts.
Until now I had just never tried doing that inside
a function. I just expected (and I think it was a
reasonable assumption) that the same construct
would be allow there.

>Also, for no particular reason, a for
>loop is required in programmes (i.e.
>when using <- ). It is a design choice.

Thank you again. At least as you and Tom pointed
out that is not necessarily a "bug". I now know to
use a for loop inside a program/function. I still
consider it a bug however, because sometimes it
allows the syntax but gives erroneous results
without any indication of an error. It is also a
poor design decision, at least from a user and
interface perspective. The documentation does not
warn about the difference... that I could find.
1-Visitor
April 21, 2010
On 4/21/2010 3:52:01 AM, cperk wrote:
>On 4/20/2010 6:21:40 AM, philipoakley
>wrote:
..
>>Also, for no particular reason, a for
>>loop is required in programmes (i.e.
>>when using <- ). It is a design choice.
>
>Thank you again. At least as you and
>Tom pointed
>out that is not necessarily a "bug". I
>now know to
>use a for loop inside a
>program/function. I still
>consider it a bug however, because
>sometimes it
>allows the syntax but gives erroneous
>results
>without any indication of an error. It
>is also a
>poor design decision, at least from a
>user and
>interface perspective. The
>documentation does not
>warn about the difference... that I
>could find.

Yes, It is what Tom calls a design bug. It is 'wrong' by design!

Philip Oakley
1-Visitor
April 20, 2010
>Do I really need to use a for loop to reproduce the behavior for local definitions inside a function? Or is it a bug ? <<br> ____________________________

Certainly not a bug. Your proposal is incomplete.
A range variable is a variable,
if you don't assign, how can you have to process ?



jmG
April 20, 2010
On 4/20/2010 1:15:59 AM, jmG wrote:

>Certainly not a bug. Your proposal is incomplete.

>A range variable is a variable, if you don't

>assign, how can you have to process ?



Of course. In my example, I was assuming the range variable was already defined over a valid range. (I guess there's all types and levels of users that might actually have missed that point, but I was just trying to be concise.)


Here's the same example on my installation of Mathcad 14.0 M030 with all compatibility options set to MC12.
1-Visitor
April 20, 2010
>Here's the same example on my installation of Mathcad 14.0 M030<<br> ___________________________

I couldn't not work with that kind of illogical setup. This is one of the reason why most of the work sheets done up to version 11 didn't work after that version and were eliminated from the repository, thus scraping the best of the Mathcad collabs or contributors ... V[3 has a single value, not a ranged value. If you never had Mathcad 11 or earlier versions, you have no idea how great Mathcad was.

jmG