Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Limiting the scope of the vectorize operator

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-13-2003
03:00 AM

08-13-2003
03:00 AM

Limiting the scope of the vectorize operator

If you apply the vectorize operator to a function that takes other functions as parameters, you have to note that the vectorization applies to the parameters as well - this can create unexpected results. The obvious solution is to apply the vectorize operator to just the function name; unfortunately, this doesn't work. the next method is to evaluate the parameter functions first, assign the results to variables and then apply the main function to these variables. Which is all a bit messy.

However, while looking through the collabatory for a way round this, I noticed the following tip from VFO, regarding prefix operators

http://collab.mathsoft.com/read?33692,11e#33692

and wondered if that might help. It does. Simply create the prefix operator place holders(PH), type the main function in the first PH and vectorize it, then type the parameter function into the second PH.

The only problem is that this method seems to be retricted to a single parameter. Using the 'x f y' form stretches it to 2 functions, but I can't think of a way of generalizing it.

Does anyone else know of a more elegant way to stop the vectorize operator applying to parameters

Stuart

However, while looking through the collabatory for a way round this, I noticed the following tip from VFO, regarding prefix operators

http://collab.mathsoft.com/read?33692,11e#33692

and wondered if that might help. It does. Simply create the prefix operator place holders(PH), type the main function in the first PH and vectorize it, then type the parameter function into the second PH.

The only problem is that this method seems to be retricted to a single parameter. Using the 'x f y' form stretches it to 2 functions, but I can't think of a way of generalizing it.

Does anyone else know of a more elegant way to stop the vectorize operator applying to parameters

Stuart

Labels:

12 REPLIES 12

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-13-2003
03:00 AM

08-13-2003
03:00 AM

Limiting the scope of the vectorize operator

Sorry, that doesn't really work. As per the documentation, the vectorize operation applied to a simple variable is just decorative. You need a test case where vectorizing actually makes a difference. In your example, it didn't. Your expected result with or without vectorization was the same, and that's what you got -- not because the vectorization was limited as you wanted, but because it did not apply at all.

Tom Gutman

Tom Gutman

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-13-2003
03:00 AM

08-13-2003
03:00 AM

Limiting the scope of the vectorize operator

You are quite right, Tom.

So the question becomes more general:

Is there a method of limiting the scope of the vectorize operator?

What are the benefits of vectorize operator acting like it does? Is it a more 'intuitive' behaviour than just applying a function (operator) to the 'normal' results of functional parameters?

Stuart

So the question becomes more general:

Is there a method of limiting the scope of the vectorize operator?

What are the benefits of vectorize operator acting like it does? Is it a more 'intuitive' behaviour than just applying a function (operator) to the 'normal' results of functional parameters?

Stuart

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-13-2003
03:00 AM

08-13-2003
03:00 AM

Limiting the scope of the vectorize operator

>>What are the benefits of vectorize operator acting like it does? <<

The ability to apply vectorize to a complete expression rather than having to apply it to each operator separately. Vectorization directly applies only to a single operator, causing it to be applied element by element. Mathcad extends that by recursively applying it to each of the operands. This is normally what is wanted. The typical use is that one starts with an expression, often complicated, written for scalar operands and one wants to evaluate it over multiple sets of data. The current definition allows one to just vectorize the whole expression. If it were not applied recursively to the operands, only would have to apply it to each operator, with the exception of those that automatically vectorize (which itself may vary depending on the shape of the arrays).

Note that a function evaluation is no different, being just an instance of the apply operator (which may be written in several different forms).

The problem only comes up when you have a mixed form to start with, with some scalar and some vector operands and operators. Now you only want to vectorize the scalar operations.

And even that is not so clear. If a part of the expression involves a*v, where a is a scalar and v is a vector, then to vectorize with respect to a requires generating a nested vector, where each element of a multiplies the complete vector v. There is no standard notation for that, you have to write out something more explicit, using explicit or implicit iteration.

So I think that is where it will stay at. If you have a simple purely scalar expression, you can just vectorize it to use multiple data sets. If yout expression is mixed, you have to do the work of vectorizing it with respect to selected variables yourself.

Tom Gutman

The ability to apply vectorize to a complete expression rather than having to apply it to each operator separately. Vectorization directly applies only to a single operator, causing it to be applied element by element. Mathcad extends that by recursively applying it to each of the operands. This is normally what is wanted. The typical use is that one starts with an expression, often complicated, written for scalar operands and one wants to evaluate it over multiple sets of data. The current definition allows one to just vectorize the whole expression. If it were not applied recursively to the operands, only would have to apply it to each operator, with the exception of those that automatically vectorize (which itself may vary depending on the shape of the arrays).

Note that a function evaluation is no different, being just an instance of the apply operator (which may be written in several different forms).

The problem only comes up when you have a mixed form to start with, with some scalar and some vector operands and operators. Now you only want to vectorize the scalar operations.

And even that is not so clear. If a part of the expression involves a*v, where a is a scalar and v is a vector, then to vectorize with respect to a requires generating a nested vector, where each element of a multiplies the complete vector v. There is no standard notation for that, you have to write out something more explicit, using explicit or implicit iteration.

So I think that is where it will stay at. If you have a simple purely scalar expression, you can just vectorize it to use multiple data sets. If yout expression is mixed, you have to do the work of vectorizing it with respect to selected variables yourself.

Tom Gutman

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-13-2003
03:00 AM

08-13-2003
03:00 AM

Limiting the scope of the vectorize operator

I love that thread:

Vectorize is sometimes quick for a simple use,

like graph.

The best way is to create a vector right at the

stage of defining the range variable

Create the dependent variable as a vector.

No more headache.

The hint in there is that Mathcad displays in

vector format. But that does not create a vector

like for instance result of RK odesolve.

A good work sheet that resumes well this matter

is the work sheet (� one month old) multiplot.

For other model technique: do like Robert.

jmG

Vectorize is sometimes quick for a simple use,

like graph.

The best way is to create a vector right at the

stage of defining the range variable

Create the dependent variable as a vector.

No more headache.

The hint in there is that Mathcad displays in

vector format. But that does not create a vector

like for instance result of RK odesolve.

A good work sheet that resumes well this matter

is the work sheet (� one month old) multiplot.

For other model technique: do like Robert.

jmG

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2019
03:55 AM

03-21-2019
03:55 AM

Re: Limiting the scope of the vectorize operator

@StuartBruff wrote:

You are quite right, Tom.

So the question becomes more general:

Is there a method of limiting the scope of the vectorize operator?

What are the benefits of vectorize operator acting like it does? Is it a more 'intuitive' behaviour than just applying a function (operator) to the 'normal' results of functional parameters?

Stuart

Stuart, your question is wonderful. Let me describe what I have come across. I want to compute the following, over the ring of integer arithmetic modulo 5:

A*B,

where A and B are (3x3) matrices. The ring of modulo 5 integer arithmetic forms a finite field (in case you are interested), and it has only 5 elements, namely 0, 1, 2, 3, 4. Thus, the matrices A, B, and A*B should have only integer entries, and those entries should be not less than 0 and not more than 5. To do this within MathCAD is already a bit more involved than it should be, because the modular arithmetic function misses the mark in the first place. I can fix that, however. I defined Mod(x,n)=mod(2*n+mod(x,n),n), and upon any integer inputs x and n, this "Modified modulus" function always outputs an integer value y between 0 and 4 inclusive, and this value y always has the property that the difference between x and y is a multiple of n. Thus this function produces what might reasonably be called "the Principle value" of the congruence class of x modulo n. This is very useful for a variety of reasons.

Now, more than a decade ago, I wrote several MathCAD documents that used my Principle value Modulus function. Some of them were designed to multiply matrices or to perform other matrix or vector operations related to problem solving in Linear Algebra over a finite field, or even over a finite ring that is not a field. For example, over the five element field, if A is the (2x2) matrix whose rows are [1 2] and [3 4], respectively, and if B is the (2x3) matrix whose rows are [0 4 3] and [4 2 1], respectively, then a reasonably educated mathematics student can compute A*B, and the result is the matrix whose rows are [3 3 0] and [1 0 3], respectively. In order to get MathCAD to do this over a decade ago, I wrote my code using the vectorize operator, and it worked beautifully; however, in th document I created today, it works not at all. Guess why...

Well, maybe you guessed it, or maybe user ptc-1368288 can explain to you why none of my documents that worked with older versions of MathCAD now can be fixed... Attached is a MathCAD document that would have worked in MathCAD 14 or earlier, but now is trash, strictly because the behavior of the vectorize operator has been changed by the programmers with no option for implementing the older version of the vectorize operator.

When I noticed this new behavior of the vectorize operator was misbehaving, I looked up the vectorize operator in the help system. Here is what I found, not in the help file for vectorize itself, but in the associated QuickSheet:

"The vectorize operator affects all function applications underneath the arrow, not just the topmost function. Versions of Mathcad prior to 2000 ignored vectorization of user-defined functions which called built-in functions that ignore vectorization, but this is no longer the case, and may affect the evaluation of old worksheets. "

This is a "We broke it to help you because we know better than you do what you need in order to get the answer you need. Oh, you did not need or want the answer we gave you. Too bad."

It's the middle finger of corporate America to the educated user.

So to answer your question a bit more succinctly, the benefit of this particular change is to create a programmers "bomb" that self-destructs the product so that some users will think they need to hire the programmer to fix it. I don't see it as a benefit to the user who understands recursion and already built in the recursion down into a formula of the vectorize operator when needed.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2019
03:06 AM

03-21-2019
03:06 AM

Re: Limiting the scope of the vectorize operator

The link you provided is dead to me.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2019
02:54 PM

03-21-2019
02:54 PM

Re: Limiting the scope of the vectorize operator

There's a good, but sad explanation as to why:

The original thread is over 15 years old (look at the date!), and this forum has gone over at least two platform moves in the last 5 years, each time with a loss of content.

Success!

Luc

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-03-2019
09:12 AM

04-03-2019
09:12 AM

Re: Limiting the scope of the vectorize operator

Does any employee of PTC ever read any of these posts and try to do something about t

@LucMeekes wrote:

There's a good, but sad explanation as to why:

The original thread is over 15 years old (look at the date!), and this forum has gone over at least two platform moves in the last 5 years, each time with a loss of content.

Success!

Luc

hese issues?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-03-2019
09:24 AM

04-03-2019
09:24 AM

Re: Limiting the scope of the vectorize operator

There's no telling how many PTC employees read any of the posts in this forum.

Judging by the reactions it can't be much (or all of them are reading all posts and they spend the day laughing so much that there's no time left to react).

If you need any old post in particular, you may want to ask Jaime_Lee if she can still find it.

Success!

Luc

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-03-2019
09:42 AM

04-03-2019
09:42 AM

Re: Limiting the scope of the vectorize operator

@LucMeekes wrote:

There's no telling how many PTC employees read any of the posts in this forum.

Judging by the reactions it can't be much (or all of them are reading all posts and they spend the day laughing so much that there's no time left to react).

If you need any old post in particular, you may want to ask Jaime_Lee if she can still find it.

Success!

Luc

I'm not sure what you mean by "any old post in particular". If you take a look at my posts, you'll see that no issue I've raised in the twenty years or so I've been using MathCAD has been addressed successfully by the programmers at PTC. There really aren't that many, but when I've looked through the forums, I see that many users are posting issues that are never fixed, as can be seen by the fact that they come back to their post and as I have done, comment that the company has not repaired the issue. Then like this thread, the development team seems to think that they did users a service by ruining the vectorize operator.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-03-2019
09:37 AM

04-03-2019
09:37 AM

Re: Limiting the scope of the vectorize operator

By the way, you point out that there is loss of content for each platform change and you started this post off saying you were giving a good but sad explanation. If it's sad and there is loss of content, why is that "Success!"???

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-03-2019
09:56 AM

04-03-2019
09:56 AM

Re: Limiting the scope of the vectorize operator

That's because I end most of my contributions to this forum with this. I leave it up to the reader to interpret whether it is comforting, encouraging or sarcastic.

Success!

Luc