8-Gravel
August 3, 2022
Solved
Returning Vector
- August 3, 2022
- 1 reply
- 1703 views
I do not understand why the result being returned is a vector. I am passing a value for both R and Y
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
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.