Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
I do not understand why the result being returned is a vector. I am passing a value for both R and Y
Solved! Go to Solution.
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
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
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
@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.
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
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
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