Jump to content

Vector products: Difference between revisions

→‎{{header|REXX}}: Improve readability and make it ooRexx conform
(→‎{{header|REXX}}: Improve readability and make it ooRexx conform)
Line 4,630:
 
=={{header|REXX}}==
<syntaxhighlight lang="rexx">/*REXX program computes the products: dot, cross, scalar triple, and vector triple.*/
a= 3 4 5
b= 4 3 5 b= 4 3 5 /*(positive numbers don't need quotes.)*/
c= "'-5 -12 -13"'
callCall tellV 'vector A =', a /*show the A vector, aligned numbers.*/
callCall tellV '"vector B ='", b /* " " B " " " */
callCall tellV '"vector C ='", c /* " " C " " " */
Say ''
say
callCall tellV ' dot product [A∙BA·B] =', dot(a, b)
callCall tellV 'cross product [AxB] =', cross(a, b)
callCall tellV 'scalar triple product [A∙(BxC)] =', dot(a, cross(b, c) )
callCall tellV 'vector triple product [Ax(BxC)] =', cross(a, cross(b, c) )
exit 0 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
tellV: procedure; parse arg name,x y z; w=max(4,length(x),length(y),length(z)) /*max Wwidth */
saySay right(name,4033) right(x,w) right(y,w) right(z,w); /*show vector.*/ return< */syntaxhighlight>
Return</syntaxhighlight>
{{out|output|text=&nbsp; when using the default internal inputs:}}
<pre>
vector A = 3 4 5
vector B = 4 3 5
vector C = -5 -12 -13
 
dot product [A∙BAÀB] = 49
cross product [AxB] = 5 5 -7
scalar triple product [A∙(BxC)] = 6
vector triple product [Ax(BxC)] = -267 204 -3</pre>
</pre>
 
=={{header|Ring}}==
2,295

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.