Vector products: Difference between revisions

Added solution for Action!
(Add CLU)
(Added solution for Action!)
Line 71:
a . (b x c) = 6
a x (b x c) = (-267, 204, -3)
</pre>
 
=={{header|Action!}}==
<lang Action!>TYPE Vector=[INT x,y,z]
 
PROC CreateVector(INT vx,vy,vz Vector POINTER v)
v.x=vx v.y=vy v.z=vz
RETURN
 
PROC PrintVector(Vector POINTER v)
PrintF("(%I,%I,%I)",v.x,v.y,v.z)
RETURN
 
INT FUNC DotProduct(Vector POINTER v1,v2)
INT res
 
res=v1.x*v2.x ;calculation split into parts
res==+v1.y*v2.y ;otherwise incorrect result
res==+v1.z*v2.z ;is returned
RETURN (res)
 
PROC CrossProduct(Vector POINTER v1,v2,res)
res.x=v1.y*v2.z ;calculation split into parts
res.x==-v1.z*v2.y ;otherwise incorrect result
res.y=v1.z*v2.x ;is returned
res.y==-v1.x*v2.z
res.z=v1.x*v2.y
res.z==-v1.y*v2.x
RETURN
 
PROC Main()
Vector a,b,c,d,e
INT res
 
CreateVector(3,4,5,a)
CreateVector(4,3,5,b)
CreateVector(-5,-12,-13,c)
 
Print("a=") PrintVector(a) PutE()
Print("b=") PrintVector(b) PutE()
Print("c=") PrintVector(c) PutE()
PutE()
res=DotProduct(a,b)
PrintF("a.b=%I%E",res)
 
CrossProduct(a,b,d)
Print("axb=") PrintVector(d) PutE()
 
CrossProduct(b,c,d)
res=DotProduct(a,d)
PrintF("a.(bxc)=%I%E",res)
 
CrossProduct(b,c,d)
CrossProduct(a,d,e)
Print("ax(bxc)=") PrintVector(e) PutE()
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Vector_products.png Screenshot from Atari 8-bit computer]
<pre>
a=(3,4,5)
b=(4,3,5)
c=(-5,-12,-13)
 
a.b=49
axb=(5,5,-7)
a.(bxc)=6
ax(bxc)=(-267,204,-3)
</pre>
 
Anonymous user