Vector products: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: simplified some code. |
Updated to work with Nim 1.4: replaced "~×" and "~•" with "cross" and "dot" as the infix notation no longer works. Used "strformat". Other miscellaneous changes. |
||
Line 3,026:
=={{header|Nim}}==
<lang nim>import strformat, strutils
type Vector3 = array[1..3, float]
proc `$`(a: Vector3): string =
result = "
result.add ')'
▲ for i, x in a:
▲ result.add ", "
▲ result.add "]"
▲proc `~⨯`(a, b: Vector3): Vector3 =
result = [a[2]*b[3] - a[3]*b[2], a[3]*b[1] - a[1]*b[3], a[1]*b[2] - a[2]*b[1]]
proc
for i in a.low..a.high:
result += a[i] * b[i]
proc
proc
let
Line 3,055 ⟶ 3,052:
b = [4.0, 3.0, 5.0]
c = [-5.0, -12.0, -13.0]
echo &"a
echo &"a .
echo &"a
{{out}}
a • b = 49▼
<pre>a
▲a ⨯ (b ⨯ c) = [-267, 204, -3]</pre>
a . (b ⨯ c) = 6.0
a ⨯ (b ⨯ c) = (-267.0, 204.0, -3.0)</pre>
=={{header|Objeck}}==
|