Dot product: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
Basicgames (talk | contribs) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(5 intermediate revisions by 4 users not shown) | |||
Line 276:
end.
</syntaxhighlight>
=={{header|Amazing Hopper}}==
Version 1:
#include <basico.h>
principal {
imprimir(producto punto( lst'1,3,(-5)', lst'4,(-2),(-1)' ),NL)
terminar
}
</syntaxhighlight>
{{out}}
<pre>
3.00000
</pre>
Version 2:
<syntaxhighlight lang="c">
#define maincode main: {1}do
#define this {1}do
#defn out {"\n"}print
#define dotp mul;stats(0)
#defn lst(*) {"\033"} *;mklist;
#define ready {0}return
#define decim _X_DECIM=0, mov(_X_DECIM),prec(_X_DECIM),{1}do
main code{
{0}decim{
"A.B = "
this{
lst (1,3,(-5)), lst (4,(-2),(-1))
} dotp
} ready
</syntaxhighlight>
{{out}}
<pre>
A.B = 3
</pre>
Version 3:
<syntaxhighlight lang="c">
#defn dotp(_X_,_Y_) #ATOM#CMPLX;#ATOM#CMPLX; mul; stats(0)
#defn lst(*) {"\033"} *;mklist;
#defn out(*) *;{"\n"}print
#defn code(*) main:; *; {"0"};return
code( out( dotp( lst (1,3,(-5)), lst (4,(-2),(-1)) ) ) )
</syntaxhighlight>
{{out}}
<pre>
3.00000
</pre>
<p>etc...</p>
=={{header|APL}}==
Line 871 ⟶ 923:
arraysize n, a
for i = 0 to n - 1
let s = s + a[i] * b[i]
Line 877 ⟶ 929:
next i
print s</syntaxhighlight>
{{out| Output}}<pre>3</pre>
▲end</syntaxhighlight>
=={{header|Crystal}}==
Line 1,031 ⟶ 1,082:
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
func dotprod a[] b[]
▲ r = 0
for i to len a[]
r += a[i] * b[i]
.
return r
.
</syntaxhighlight>
Line 1,392 ⟶ 1,442:
{{FormulaeEntry|page=https://formulae.org/?script=examples/Dot_product}}
'''Solution'''
Dot product is intrinsically supported in Fōrmulæ.
'''Test case'''
[[File:Fōrmulæ - Dot product 01.png]]
[[File:Fōrmulæ - Dot product 02.png]]
'''Special cases'''
[[File:Fōrmulæ - Dot product 03.png]]
[[File:Fōrmulæ - Dot product 04.png]]
[[File:Fōrmulæ - Dot product 05.png]]
[[File:Fōrmulæ - Dot product 06.png]]
'''Programmed.''' A program can be created to calculate the dot product of two vectors:
[[File:Fōrmulæ - Dot product 07.png]]
=={{header|GAP}}==
Line 3,502 ⟶ 3,576:
=={{header|Wren}}==
<syntaxhighlight lang="
construct new(a) {
if (a.type != List || a.count == 0 || !a.all { |i| i is Num }) {
Line 3,537 ⟶ 3,611:
{{libheader|Wren-vector}}
Alternatively, using the above module:
<syntaxhighlight lang="
var v1 = Vector3.new(1, 3, -5)
|