Vector products: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: Improve readability and make it ooRexx conform)
Line 4,630: Line 4,630:


=={{header|REXX}}==
=={{header|REXX}}==
<syntaxhighlight lang="rexx">/*REXX program computes the products: dot, cross, scalar triple, and vector triple.*/
<syntaxhighlight lang="rexx">/*REXX program computes the products: dot, cross, scalar triple, and vector triple.*/
a= 3 4 5
a= 3 4 5
b= 4 3 5 /*(positive numbers don't need quotes.)*/
b= 4 3 5 /*(positive numbers don't need quotes.)*/
c= "-5 -12 -13"
c= '-5 -12 -13'
call tellV 'vector A =', a /*show the A vector, aligned numbers.*/
Call tellV 'vector A =', a /*show the A vector, aligned numbers.*/
call tellV 'vector B =', b /* " " B " " " */
Call tellV "vector B =", b /* " " B " " " */
call tellV 'vector C =', c /* " " C " " " */
Call tellV "vector C =", c /* " " C " " " */
Say ''
say
call tellV ' dot product [A∙B] =', dot(a, b)
Call tellV ' dot product [A·B] =', dot(a,b)
call tellV 'cross product [AxB] =', cross(a, b)
Call tellV 'cross product [AxB] =', cross(a,b)
call tellV 'scalar triple product [A∙(BxC)] =', dot(a, cross(b, c) )
Call tellV 'scalar triple product [(BxC)] =', dot(a,cross(b,c))
call tellV 'vector triple product [Ax(BxC)] =', cross(a, cross(b, c) )
Call tellV 'vector triple product [Ax(BxC)] =', cross(a,cross(b,c))
exit 0 /*stick a fork in it, we're all done. */
Exit /*stick a fork in it, we're all done. */
/*---------------------------------------------------------------------------*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
cross: Procedure
cross: procedure; arg $1 $2 $3,@1 @2 @3; return $2*@3 -$3*@2 $3*@1 -$1*@3 $1*@2 -$2*@1
Arg a b c, u v w
dot: procedure; arg $1 $2 $3,@1 @2 @3; return $1*@1 + $2*@2 + $3*@3
Return b*w-c*v c*u-a*w a*v-b*u
/*──────────────────────────────────────────────────────────────────────────────────────*/
dot: Procedure
tellV: procedure; parse arg name,x y z; w=max(4,length(x),length(y),length(z)) /*max W*/
Arg a b c, u v w
say right(name,40) right(x,w) right(y,w) right(z,w); /*show vector.*/ return</syntaxhighlight>
Return a*u + b*v + c*w
{{out|output|text=&nbsp; when using the default internal inputs:}}
/*---------------------------------------------------------------------------*/
tellV: Procedure
Parse Arg name,x y z
w=max(4,length(x),length(y),length(z)) /*max width */
Say right(name,33) right(x,w) right(y,w) right(z,w) /*show vector. */
Return</syntaxhighlight>
{{out|output|text=&nbsp; when using the default internal inputs:}}
<pre>
<pre>
vector A = 3 4 5
vector A = 3 4 5
vector B = 4 3 5
vector B = 4 3 5
vector C = -5 -12 -13
vector C = -5 -12 -13


dot product [A∙B] = 49
dot product [AÀB] = 49
cross product [AxB] = 5 5 -7
cross product [AxB] = 5 5 -7
scalar triple product [A∙(BxC)] = 6
scalar triple product [(BxC)] = 6
vector triple product [Ax(BxC)] = -267 204 -3
vector triple product [Ax(BxC)] = -267 204 -3</pre>
</pre>


=={{header|Ring}}==
=={{header|Ring}}==