How to resolve the algorithm Dot product step by step in the Seed7 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Dot product step by step in the Seed7 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 Seed7 programming language
Source code in the seed7 programming language
$ include "seed7_05.s7i";
$ syntax expr: .().dot.() is -> 6; # priority of dot operator
const func integer: (in array integer: a) dot (in array integer: b) is func
result
var integer: sum is 0;
local
var integer: index is 0;
begin
if length(a) <> length(b) then
raise RANGE_ERROR;
else
for index range 1 to length(a) do
sum +:= a[index] * b[index];
end for;
end if;
end func;
const proc: main is func
begin
writeln([](1, 3, -5) dot [](4, -2, -1));
end func;
You may also check:How to resolve the algorithm Inheritance/Multiple step by step in the zkl programming language
You may also check:How to resolve the algorithm Cantor set step by step in the Phixmonti programming language
You may also check:How to resolve the algorithm Subleq step by step in the PureBasic programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Raven programming language
You may also check:How to resolve the algorithm Convert decimal number to rational step by step in the Kotlin programming language