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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Returning Vector

AS_9781967
7-Bedrock

Returning Vector

I do not understand why the result being returned is a vector.  I am passing a value for both R and Y

1 ACCEPTED SOLUTION

Accepted Solutions

Hmmm, your initial question was why the result is a vector.

Now it seems that you actually expect a vector but are puzzled as of the results being wrong when you feed a vector Y in your function P.

The reason for this is that, when Y is a vector, all three factors used in the definition of your function P are vectors. So you are multiplying three vectors. This is done left to right. The first two vectors are multiplied and ... of course Prime must use the dot product (inner vector product) to do so. The result is a scalar andt thats not what you wanted to be calculated. This scalar is then multiplied by the third vector and so the total result is again a vector, but of course with wrong values.

When you call function P with a vector Y, you want Prime to do the calculation individually with every value in the vector Y and not use vector arithmetic. This is exactly what vectorization is made for (Ctrl-Shift-6, at least on my keyboard, or via the operators menu) - note the arrow over the expression

Werner_E_0-1659671658392.png

BTW, you don't have to make R an argument of functions Z and A as its not used there.

 

As an alternative you may already apply vectorization when you define P(R,Y). In that case you can omit the vectorization operator when you call the function

Werner_E_1-1659671780485.png

 

P.S.: Some further example about vectorization can be seen here: https://community.ptc.com/t5/Mathcad/Trouble-returning-array/m-p/811764/highlight/true#M202102

 

 

View solution in original post

3 REPLIES 3


@AS_9781967 wrote:

I do not understand why the result being returned is a vector.  I am passing a value for both R and Y


So why did you expect something else other than a vector?

Your definition of the function P uses the predefined vector Z which then multiplied by some scalars depending on R and Y. So the result must be a vector.

Werner_E_0-1659562745996.png

 

Thanks Werner for the information. I made changes to Z and made it as function. However, I am not able to understand why there are different results when evaluated individually any idea?

Hmmm, your initial question was why the result is a vector.

Now it seems that you actually expect a vector but are puzzled as of the results being wrong when you feed a vector Y in your function P.

The reason for this is that, when Y is a vector, all three factors used in the definition of your function P are vectors. So you are multiplying three vectors. This is done left to right. The first two vectors are multiplied and ... of course Prime must use the dot product (inner vector product) to do so. The result is a scalar andt thats not what you wanted to be calculated. This scalar is then multiplied by the third vector and so the total result is again a vector, but of course with wrong values.

When you call function P with a vector Y, you want Prime to do the calculation individually with every value in the vector Y and not use vector arithmetic. This is exactly what vectorization is made for (Ctrl-Shift-6, at least on my keyboard, or via the operators menu) - note the arrow over the expression

Werner_E_0-1659671658392.png

BTW, you don't have to make R an argument of functions Z and A as its not used there.

 

As an alternative you may already apply vectorization when you define P(R,Y). In that case you can omit the vectorization operator when you call the function

Werner_E_1-1659671780485.png

 

P.S.: Some further example about vectorization can be seen here: https://community.ptc.com/t5/Mathcad/Trouble-returning-array/m-p/811764/highlight/true#M202102

 

 

Top Tags