Skip to main content
1-Visitor
December 13, 2013
Question

Mathcad 2.0 won't let me define this as a variable

  • December 13, 2013
  • 6 replies
  • 6822 views

See the attached image;

mathcadproblem.PNG

Why can it process a+3 and give me a perfectly good answer, but go to define said answer as its own variable B and it won't let me??? How do I do this?

6 replies

19-Tanzanite
December 13, 2013

You need to look up the difference between a range variable and a vector.

vectors.PNG

Alan

12-Amethyst
December 13, 2013

I don't know if it is intentional or not but you can make prime accept this by adding the range variable as a subscript to the b in the assignment:

Capture.PNG

NB: it only works for integer ranges.

I have also changed the 'ORIGIN' to 1 to match your range; If you don't do this the b will contain 0,4,5,6,7.

But it is a global assignment so it will affect every array defined.

If this is a problem & ORIGIN=0 is required, then you need to change b[a to b[a-1 (in this case)

Regards

Andy

25-Diamond I
December 13, 2013

Its important to learn the difference between ranges and vectors!

a is a range variable, not a vector even if the evaluation of a or a+3 might look like a vector (which was not a good choice by Mathcad anyway).

A range variable may be seen as kind of an implicit for-loop.

Range variables should be used in a limited way only

  • indexing and accessing vectors and matrices
  • as the independent variable in plotting a function
  • in programs at for-loops

Create a as a vector and your assignment will work.

The problem exist since the beginnings of Mathcad and always was a pitfall for new users. I attach a pdf of two files by Stuart Bruff about Vectors vs. Ranges.

25-Diamond I
December 13, 2013

There is a way to quickly turn a range variable into a vector by adding an inline evaluation. I am not sure if thats intentional and as far as I am aware of this trick is undocumented. So I guess we should not rely our worksheets on it too heavily.

13.12.png

1-Visitor
December 13, 2013

I was able to get this to work both with the subscript based matrix method, as well as by putting in the =sign.

The problem I am now finding is for what I am really trying to do, I want to use the values y1, and y2 in subscripts. Doing this kind of makes it hard to do the subscript based matrix A Westerman showed, On the other hand, having to put the 2nd equals sign in after the definition works but leads to a very inefficient use of space. Any ideas?

reply.PNG

25-Diamond I
December 14, 2013

The problem I am now finding is for what I am really trying to do, I want to use the values y1, and y2 in subscripts.

As Alan already wrote - you can't, as subscripts must be integers. Probably I shouldn't have suggested the method using inline evaluation, but didn't recommend it anyway.

The usual way for creating a vector "by hand" is using an auxiliary range variable. You may also use a programming approach, but this may be considered too cumbersome:

v1.png

You may use the inline evaluation trick, its quick and dirty but not documented and so not recommended. The displayed vector can be made smaller to save space

v2.png

You may also consider using a user written auxiliary function, especially if you have more vectors to create in your sheet or you are too lazy to calculate how "long" your range variable has to be 😉

v3.png

I attach the sheet in Prime2 format.

EDIT: There was an error in the last routine which is now fixed

25-Diamond I
December 15, 2013

Forgot to mention a more "legal" (hope so) way to convert a range into a vector.

v4.png

24-Ruby IV
December 14, 2013

adam miller wrote:

See the attached image;

mathcadproblem.PNG

Why can it process a+3 and give me a perfectly good answer, but go to define said answer as its own variable B and it won't let me??? How do I do this?

In Prime 3 with a Table:

ab.png

25-Diamond I
December 14, 2013

Valery Ochkov wrote:

In Prime 3 with a Table:

A bit too cumbersome for the 101-element vector Adam needs, don't you think so, too?

24-Ruby IV
December 14, 2013

Werner Exinger wrote:

Valery Ochkov wrote:

In Prime 3 with a Table:

A bit too cumbersome for the 101-element vector Adam needs, don't you think so, too?

Pardon, I do not quit understand the topic.