Jump to content

Vector products: Difference between revisions

Added BBC BASIC
m (→‎{{header|REXX}}: ordered subroutines in alphabetical order, removed blank lines, added whitespace, changed comments. -- ~~~~)
(Added BBC BASIC)
Line 236:
a.(b x c) = 6
a x (b x c) = [ -267 204 -3 ]
</pre>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> DIM a(2), b(2), c(2), d(2)
a() = 3, 4, 5
b() = 4, 3, 5
c() = -5, -12, -13
PRINT "a . b = "; FNdot(a(),b())
PROCcross(a(),b(),d())
PRINT "a x b = (";d(0)", ";d(1)", ";d(2)")"
PRINT "a . (b x c) = "; FNscalartriple(a(),b(),c())
PROCvectortriple(a(),b(),c(),d())
PRINT "a x (b x c) = (";d(0)", ";d(1)", ";d(2)")"
END
DEF FNdot(A(),B())
LOCAL C() : DIM C(0,0)
C() = A().B()
= C(0,0)
DEF PROCcross(A(),B(),C())
C() = A(1)*B(2)-A(2)*B(1), A(2)*B(0)-A(0)*B(2), A(0)*B(1)-A(1)*B(0)
ENDPROC
DEF FNscalartriple(A(),B(),C())
LOCAL D() : DIM D(2)
PROCcross(B(),C(),D())
= FNdot(A(),D())
DEF PROCvectortriple(A(),B(),C(),D())
PROCcross(B(),C(),D())
PROCcross(A(),D(),D())
ENDPROC</lang>
Output:
<pre>
a . b = 49
a x b = (5, 5, -7)
a . (b x c) = 6
a x (b x c) = (-267, 204, -3)
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.