How to resolve the algorithm Dot product step by step in the Icon and Unicon programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Dot product step by step in the Icon and Unicon 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 Icon and Unicon programming language
Source code in the icon programming language
procedure main()
write("a dot b := ",dotproduct([1, 3, -5],[4, -2, -1]))
end
procedure dotproduct(a,b) #: return dot product of vectors a & b or error
if *a ~= *b & type(a) == type(b) == "list" then runerr(205,a) # invalid value
every (dp := 0) +:= a[i := 1 to *a] * b[i]
return dp
end
You may also check:How to resolve the algorithm Munchausen numbers step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Simple windowed application step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm A+B step by step in the Self programming language
You may also check:How to resolve the algorithm Executable library step by step in the Perl programming language
You may also check:How to resolve the algorithm Brownian tree step by step in the JavaScript programming language