Vector Arguments in Functions
5 posts
• Page 1 of 1
Vector Arguments in Functions
Consider the simple userdefined function below. The function Poly(x y) works correctly with both x and y scalars. It also works correctly with: (1) x scalar and y vector; and (2) x vector and y scalar. What modification to the function is required get the correct value of the output if both x and y are vectors? If both of the input vectors are rank 1, the output should be a matrix of rank 2.
∇
z←Poly(x y)
z←10+(x*2)+y*3
∇
If this matter is covered in the Dyalog documentation, please provide the reference.
∇
z←Poly(x y)
z←10+(x*2)+y*3
∇
If this matter is covered in the Dyalog documentation, please provide the reference.
 REMINGTON30
 Posts: 19
 Joined: Fri Aug 11, 2017 2:17 pm
Re: Vector Arguments in Functions
Outer Product
∇
z←Poly(x y)
z←10+(x*2)∘.+y*3
∇
And welcome to the forums.
∇
z←Poly(x y)
z←10+(x*2)∘.+y*3
∇
And welcome to the forums.

Phil Last  Posts: 557
 Joined: Thu Jun 18, 2009 6:29 pm
Re: Vector Arguments in Functions
Thanks Phil. I have some more complicated functions that work fine with scalar inputs but fail with vector inputs. I may post some of them on the Forum later.
 REMINGTON30
 Posts: 19
 Joined: Fri Aug 11, 2017 2:17 pm
Re: Vector Arguments in Functions
I may be about to confuse you by my use of the words "function", "argument" and "operator". APL is an infix notation. Its functions, be they primitive, defined or derived, take one (right) or two (left and right) array arguments and return an array. Your definition of Poly uses a fairly new extension to Dyalog APL that permits nonAPLlike functional notation whose (x y) is not two arguments but one. Poly is monadic.
If its header were
Functions
If you write a function that uses only primitive scalar functions then your function is guaranteed to be scalar itself. Had you written Poly as
If its header were
z←x Poly yyour function would be identical internally but called with the arguments either side, that is, dyadic . It would then be applicable to various operators: reduction (/) scan (\) outer (∘.) and inner product (.) &c. which take dyadic functions as operands.
Functions
+  × ÷  ⌊ ⌈ * ⍟ ○ ! ~ ? ∊ ^ ∨ ⍲ ⍱ < ≤ = ≥ > ≠are all scalar functions which means they return an array that conforms to their single (right) argument or both conforming (left and right) arguments  where conforming means agreeing in rank and shape or having one argument a scalar.
If you write a function that uses only primitive scalar functions then your function is guaranteed to be scalar itself. Had you written Poly as
∇ z←x Poly yyou wouldn't need to amend it to take advantage of the above.
[1] z←10+(x*2)+y*3
∇
1 Poly 2 ⍝ scalar/scalar
19
1 Poly 2 3 4 ⍝ scalar/vector
19 38 75
1 2 3 Poly 2 ⍝ vector/scalar
19 22 27
1 2 3 Poly 2 3 4 ⍝ conforming vectors
19 41 83
1 2 3 Poly 2 3 4 5 ⍝ nonconforming vectors
LENGTH ERROR
Poly[1] z←10+(x*2)+y*3
∧
→
1 2 3 ∘.Poly 2 3 4 5 ⍝ nonconforming  outer product
19 38 75 136
22 41 78 139
27 46 83 144

Phil Last  Posts: 557
 Joined: Thu Jun 18, 2009 6:29 pm
Re: Vector Arguments in Functions
Thank you Phil. I am a beginner at APL and have have only about two months of parttime practice and no professional instruction. Learning from 1970's and 1980's books on APL and the excellent Dyalog documents has been a good experience. At this point, a few of my old FORTRAN and Mathcad codes have been successfully coded in APL.
I have learned a great deal from your comments. Many of the functions I have written use the Namelist type of right argument Function(x y z w). I will try converting some of them to a dyadic form X Function Y with both X and Y vectors. One current function I have solves the supersonic conical flow problem including the conical shock wave angle, corresponding cone angle, and all temperature, pressure, and velocity conditions between the shock wave and the cone surface. The function works great as long as all of the input arguments (currently a Namelist), including the upstream Mach number, are scalar. Based on your comments, I will try to modify the function to accept a vector input for the Mach number and, perhaps, other input arguments as well.
Again, thank you.
I have learned a great deal from your comments. Many of the functions I have written use the Namelist type of right argument Function(x y z w). I will try converting some of them to a dyadic form X Function Y with both X and Y vectors. One current function I have solves the supersonic conical flow problem including the conical shock wave angle, corresponding cone angle, and all temperature, pressure, and velocity conditions between the shock wave and the cone surface. The function works great as long as all of the input arguments (currently a Namelist), including the upstream Mach number, are scalar. Based on your comments, I will try to modify the function to accept a vector input for the Mach number and, perhaps, other input arguments as well.
Again, thank you.
 Attachments

 Conical Shock Wave
 Shock on cone image022_small.jpg (8.29 KiB) Viewed 10893 times
 REMINGTON30
 Posts: 19
 Joined: Fri Aug 11, 2017 2:17 pm
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group