Vector products: Difference between revisions

m
→‎{{header|REXX}}: simplified some code.
m (→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics)
m (→‎{{header|REXX}}: simplified some code.)
Line 4,031:
call tellV 'vector B =', b /* " " B " " " */
call tellV 'vector C =', c /* " " C " " " */
say
call tellV ' dot product [A∙B] =', dot(a, b)
call tellV 'cross product [AxB] =', cross(a, b)
call tellV 'scalar triple product [A∙(BxC)] =', dot(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. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
cross: procedure; arg $1 $2 $3,@1 @2 @3; return $2*@3 -$3*@2 $3*@1 -$1*@3 $1*@2 -$2*@1
dot: procedure; arg $1 $2 $3,@1 @2 @3; return $1*@1 + $2*@2 + $3*@3
/*──────────────────────────────────────────────────────────────────────────────────────*/
tellV: procedure; parse arg name,x y z; w=max(4,length(x),length(y),length(z)) /*obtain name,max values.W*/
w=maxsay right(4name,40) length right(x,w), length right(y,w), length right(z,w); )/*show vector.*/ /*max width of numbers*return</lang>
{{out|output|text=&nbsp; when using the default internal inputs:}}
say right(name, 40) right(x,w) right(y,w) right(z,w) /*enforce # alignment.*/
return /* [↑] display vector*/</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
vector A = 3 4 5