|
|
Line 752: |
Line 752: |
|
</pre> |
|
</pre> |
|
|
|
|
⚫ |
|
|
⚫ |
{{works with|Fortran|95 and later}} |
|
⚫ |
Specialized for 3-dimensional vectors. |
|
⚫ |
<lang fortran>program VectorProducts |
|
|
|
|
⚫ |
real, dimension(3) :: a, b, c |
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
print *, dot_product(a, b) |
|
⚫ |
print *, cross_product(a, b) |
|
⚫ |
print *, s3_product(a, b, c) |
|
⚫ |
print *, v3_product(a, b, c) |
|
|
|
|
⚫ |
|
|
|
|
|
⚫ |
function cross_product(a, b) |
|
⚫ |
real, dimension(3) :: cross_product |
|
⚫ |
real, dimension(3), intent(in) :: a, b |
|
|
|
|
⚫ |
cross_product(1) = a(2)*b(3) - a(3)*b(2) |
|
⚫ |
cross_product(2) = a(3)*b(1) - a(1)*b(3) |
|
⚫ |
cross_product(3) = a(1)*b(2) - b(1)*a(2) |
|
⚫ |
end function cross_product |
|
|
|
|
⚫ |
function s3_product(a, b, c) |
|
⚫ |
|
|
⚫ |
real, dimension(3), intent(in) :: a, b, c |
|
|
|
|
⚫ |
s3_product = dot_product(a, cross_product(b, c)) |
|
⚫ |
|
|
|
|
|
⚫ |
function v3_product(a, b, c) |
|
⚫ |
real, dimension(3) :: v3_product |
|
⚫ |
real, dimension(3), intent(in) :: a, b, c |
|
|
|
|
⚫ |
v3_product = cross_product(a, cross_product(b, c)) |
|
⚫ |
|
|
|
|
|
⚫ |
end program VectorProducts</lang> |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
-267.000 204.000 -3.00000 |
|
⚫ |
|
|
|
=={{header|Forth}}== |
|
=={{header|Forth}}== |
|
{{works with|Forth|with a separate floating point stack.}}<lang Forth> |
|
{{works with|Forth|with a separate floating point stack.}}<lang Forth> |
Line 847: |
Line 799: |
|
a . [b x c] = 6.00000 |
|
a . [b x c] = 6.00000 |
|
a x [b x c] = -267.000 204.000 -3.00000 |
|
a x [b x c] = -267.000 204.000 -3.00000 |
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
{{works with|Fortran|95 and later}} |
|
⚫ |
Specialized for 3-dimensional vectors. |
|
⚫ |
<lang fortran>program VectorProducts |
|
|
|
|
⚫ |
real, dimension(3) :: a, b, c |
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
print *, dot_product(a, b) |
|
⚫ |
print *, cross_product(a, b) |
|
⚫ |
print *, s3_product(a, b, c) |
|
⚫ |
print *, v3_product(a, b, c) |
|
|
|
|
⚫ |
|
|
|
|
|
⚫ |
function cross_product(a, b) |
|
⚫ |
real, dimension(3) :: cross_product |
|
⚫ |
real, dimension(3), intent(in) :: a, b |
|
|
|
|
⚫ |
cross_product(1) = a(2)*b(3) - a(3)*b(2) |
|
⚫ |
cross_product(2) = a(3)*b(1) - a(1)*b(3) |
|
⚫ |
cross_product(3) = a(1)*b(2) - b(1)*a(2) |
|
⚫ |
end function cross_product |
|
|
|
|
⚫ |
function s3_product(a, b, c) |
|
⚫ |
|
|
⚫ |
real, dimension(3), intent(in) :: a, b, c |
|
|
|
|
⚫ |
s3_product = dot_product(a, cross_product(b, c)) |
|
⚫ |
|
|
|
|
|
⚫ |
function v3_product(a, b, c) |
|
⚫ |
real, dimension(3) :: v3_product |
|
⚫ |
real, dimension(3), intent(in) :: a, b, c |
|
|
|
|
⚫ |
v3_product = cross_product(a, cross_product(b, c)) |
|
⚫ |
|
|
|
|
|
⚫ |
end program VectorProducts</lang> |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
-267.000 204.000 -3.00000 |
|
</pre> |
|
</pre> |
|
|
|
|