How to resolve the algorithm Dot product step by step in the Action! programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Dot product step by step in the Action! programming language
Table of Contents
Problem Statement
Create a function/use an in-built function, to compute the dot product, also known as the scalar product of two vectors. If possible, make the vectors of arbitrary length.
As an example, compute the dot product of the vectors:
If implementing the dot product of two vectors directly:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Dot product step by step in the Action! programming language
Source code in the action! programming language
INT FUNC DotProduct(INT ARRAY v1,v2 BYTE len)
BYTE i,res
res=0
FOR i=0 TO len-1
DO
res==+v1(i)*v2(i)
OD
RETURN (res)
PROC PrintVector(INT ARRAY a BYTE size)
BYTE i
Put('[)
FOR i=0 TO size-1
DO
PrintI(a(i))
IF i
Put(',)
FI
OD
Put('])
RETURN
PROC Test(INT ARRAY v1,v2 BYTE len)
INT res
res=DotProduct(v1,v2,len)
PrintVector(v1,len)
Put('.)
PrintVector(v2,len)
Put('=)
PrintIE(res)
RETURN
PROC Main()
INT ARRAY
v1=[1 3 65531],
v2=[4 65534 65535]
Test(v1,v2,3)
RETURN
You may also check:How to resolve the algorithm Roman numerals/Decode step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Loops/Wrong ranges step by step in the Wren programming language
You may also check:How to resolve the algorithm Copy stdin to stdout step by step in the Pascal programming language
You may also check:How to resolve the algorithm Stern-Brocot sequence step by step in the Tcl programming language
You may also check:How to resolve the algorithm Primality by trial division step by step in the Cowgol programming language