September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,17 +1,16 @@
|
|||
/*REXX program computes the dot product of two equal size vectors (of any size).*/
|
||||
vectorA = ' 1 3 -5 ' /*populate vector A with some numbers*/
|
||||
vectorB = ' 4 -2 -1 ' /* " " B " " " */
|
||||
say /*display a blank line for readability.*/
|
||||
vectorA = ' 1 3 -5 ' /*populate vector A with some numbers*/
|
||||
vectorB = ' 4 -2 -1 ' /* " " B " " " */
|
||||
say 'vector A = ' vectorA /*display the elements in the vector A.*/
|
||||
say 'vector B = ' vectorB /* " " " " " " B.*/
|
||||
p=dotProd(vectorA, vectorB) /*invoke function & compute dot product*/
|
||||
p=.Prod(vectorA, vectorB) /*invoke function & compute dot product*/
|
||||
say /*display a blank line for readability.*/
|
||||
say 'dot product = ' p /*display the dot product to terminal. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
dotProd: procedure; parse arg A,B /*this function compute the dot product*/
|
||||
$=0 /*initialize the sum to 0 (zero). */
|
||||
do j=1 for words(A) /*multiply each number in the vectors. */
|
||||
$=$+word(A,j) * word(B,j) /* ··· and add the product to the sum.*/
|
||||
end /*j*/
|
||||
return $ /*return the sum to invoker of function*/
|
||||
.Prod: procedure; parse arg A,B /*this function compute the dot product*/
|
||||
$=0 /*initialize the sum to 0 (zero). */
|
||||
do j=1 for words(A) /*multiply each number in the vectors. */
|
||||
$=$+word(A,j) * word(B,j) /* ··· and add the product to the sum.*/
|
||||
end /*j*/
|
||||
return $ /*return the sum to function's invoker.*/
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
/*REXX program computes the dot product of two equal size vectors (of any size).*/
|
||||
vectorA = ' 1 3 -5 ' /*populate vector A with some numbers*/
|
||||
vectorB = ' 4 -2 -1 ' /* " " B " " " */
|
||||
say /*display a blank line for readability.*/
|
||||
vectorA = ' 1 3 -5 ' /*populate vector A with some numbers*/
|
||||
vectorB = ' 4 -2 -1 ' /* " " B " " " */
|
||||
say 'vector A = ' vectorA /*display the elements in the vector A.*/
|
||||
say 'vector B = ' vectorB /* " " " " " " B.*/
|
||||
p=.prod(vectorA, vectorB) /*invoke function & compute dot product*/
|
||||
|
|
@ -9,8 +8,6 @@ say /*display a blank line for read
|
|||
say 'dot product = ' p /*display the dot product to terminal. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
ser: say "***error*** vector " @.k ' element' j " isn't numeric: " n.k; exit 13
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
.prod: procedure; parse arg A,B /*this function compute the dot product*/
|
||||
lenA = words(A); @.1= 'A' /*the number of numbers in vector A. */
|
||||
lenB = words(B); @.2= 'B' /* " " " " " " B. */
|
||||
|
|
@ -24,8 +21,10 @@ ser: say "***error*** vector " @.k ' element' j " isn't numeric: " n.k;
|
|||
do j=1 for lenA /*multiply each number in the vectors. */
|
||||
#.1=word(A,j) /*use array to hold 2 numbers at a time*/
|
||||
#.2=word(B,j)
|
||||
do k=1 for 2; if \datatype(#.k,'N') then call ser
|
||||
do k=1 for 2; if datatype(#.k,'N') then iterate
|
||||
say "***error*** vector " @.k ' element' j,
|
||||
" isn't numeric: " n.k; exit 13
|
||||
end /*k*/
|
||||
$=$ + #.1 * #.2 /* ··· and add the product to the sum.*/
|
||||
end /*j*/
|
||||
return $ /*return the sum to invoker of function*/
|
||||
return $ /*return the sum to function's invoker.*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue