How to resolve the algorithm Dot product step by step in the Emacs Lisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Dot product step by step in the Emacs Lisp 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 Emacs Lisp programming language
Source code in the emacs programming language
(defun dot-product (v1 v2)
(let ((res 0))
(dotimes (i (length v1))
(setq res (+ (* (elt v1 i) (elt v2 i)) res)))
res))
(dot-product [1 2 3] [1 2 3]) ;=> 14
(dot-product '(1 2 3) '(1 2 3)) ;=> 14
You may also check:How to resolve the algorithm Take notes on the command line step by step in the Arturo programming language
You may also check:How to resolve the algorithm Brace expansion step by step in the Wren programming language
You may also check:How to resolve the algorithm Increment a numerical string step by step in the Frink programming language
You may also check:How to resolve the algorithm UTF-8 encode and decode step by step in the Phix programming language
You may also check:How to resolve the algorithm Subtractive generator step by step in the PicoLisp programming language