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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Dividing a vector by a constant and assigning it to a new variable

asinha-3
1-Visitor

Dividing a vector by a constant and assigning it to a new variable

Hi, In Mathcad 15 the attached commands dont cause error but it seems Mathcad Prime 3.0 flags error. Any idea about why is it giving error on Prime 3.0?

4 REPLIES 4
Werner_E
25-Diamond I
(To:asinha-3)

> In Mathcad 15 the attached commands dont cause error

Definitely wrong! Your first example with f  throws an error in MC15, too.

The reason is that f is just a range, not a vector!! You have to learn to distinguish between ranges and vectors.

Ranges should be used sparingly, just for indexing vectors and matrices (like in your second example), for the abscissa in a 2D quickplot and in a for-loop when you write a program. Otherwise you should always create vectors, like you did in the second example - omega is a true vector (if you use the correct type of index ([)).

Your second example works fine in MC15 and also in P3. As you don't provide your sheet and just show a picture without the error message we can only guess what you did wrong.

My two guesses are that you

a) did not use the correct index (you have to use the matrix index, not the literal index)

or

b) you had set the system variable ORIGIN to something greater than 0

While matrix and literal indices look similar, there is a slight difference.

So upon optical inspection of your picture I guess its a) - you used the wrong index.

Here is a pic from P3, showing the error message in the first case, then turning f into a vector to make it work (10^6 took too long for me, so I settled with 10^4) and showing that your second example works if ORIGIN is set to 0 and the matrix index is used.

Writing i:=0..111111 and then f[i:=1+9*i would have created the vector A LOT quicker than this undocumented trick with the inline evaluation shown in my picture.

WE

-MFra-
21-Topaz II
(To:asinha-3)

Hallo asinha_3, I would proceed in this way:

for asinha_3.jpg

Bye

FM

Werner_E
25-Diamond I
(To:-MFra-)

Its not necessary to set the whole array to zero before assigning the values.

It would mean that you iterate twice through the large ranges which seems inefficient

And if for some reason you like to initialize the vector with zeros, assigning the last element is more efficient

If omega is already an array and has more than 201 elements, both methods won't reset it. In this case a simple omega:=0 does the job.

I would strongly advise against using the range f as an index to a vector.

1) the result is not the vector which Anubhav is expecting, It contains a myriad of superfluous zeros and so may be unusable

2) you will get an error if the range values are not all integers

and/or are smaller than ORIGIN

So, while the main question seemed to be why the errors occur and this has already been answered (even though Anubhav isn't showing much interest anymore),  there still are a couple of ways to create that searched for vector t and I mentioned some of them already in my answer above

1) turn the range f into a vector. You can do this by the undocumented trick (which is significantly slow for large arrays) or use one of the small range2vector conversion programs which are posted here from time to time

2) Create f as vector using a proper range to index that vector

or create t directly w/o using f

The disadvantage is that you have to know the number of elements in your desired vector

3) Use a small program to create vectors of your choice - you can chose to use the same argument order as in the definition of a range.

Similar routines also were posted here from time to time and a command like this should be part of Mathcad/Prime out of the box. Unfortunately it isn't. Personally I would prefer to have the step width Delta as argument instead of the second value (and thats quite easy to implement that way).

Regards

Werner

-MFra-
21-Topaz II
(To:Werner_E)

Remarkable suggestion.

Thank You very much.

FM

Announcements

Top Tags