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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

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

ptc-5232076
1-Newbie

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

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?

11 REPLIES 11

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

vectors.PNG

Alan

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

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.

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

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

Subscripts must have integer values, so you will need to create, say, i:=0..100 and then create y1[i:= i/100 and y2:=y1-alpha. I guess you then want another variable to depend on these, but you will have to create that as a function, say fn(y1,y2), or as a double subscripted variable fn[i,j where j also runs from 0 to 100.

Alan

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

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

v4.png

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

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?

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.

Top Tags