How to resolve the algorithm Dot product step by step in the Oberon-2 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Dot product step by step in the Oberon-2 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 Oberon-2 programming language
Source code in the oberon-2 programming language
MODULE DotProduct;
IMPORT
Out := NPCT:Console;
VAR
x,y: ARRAY 3 OF LONGINT;
PROCEDURE DotProduct(a,b: ARRAY OF LONGINT): LONGINT;
VAR
resp, i: LONGINT;
BEGIN
ASSERT(LEN(a) = LEN(b));
resp := 0;
FOR i := 0 TO LEN(x) - 1 DO
INC(resp,x[i]*y[i])
END;
RETURN resp
END DotProduct;
BEGIN
x[0] := 1;y[0] := 4;
x[1] := 3;y[1] := -2;
x[2] := -5;y[2] := -1;
Out.Int(DotProduct(x,y),0);Out.Ln
END DotProduct.
You may also check:How to resolve the algorithm Stack traces step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bogosort step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Flatten a list step by step in the Burlesque programming language
You may also check:How to resolve the algorithm Gotchas step by step in the Wren programming language
You may also check:How to resolve the algorithm Levenshtein distance step by step in the TSE SAL programming language