Fortran program for dot product of three vectors or scalar triple product

Scalar Product of three vectors: Scalar Product or dot product of three vectors is also known as Scalar Triple product and is defined by: \vec{a}.\vec{b}\times \vec{c}

And \vec{a}.\vec{b}\times \vec{c} = \vec{b}.\vec{c}\times \vec{a} = \vec{c}.\vec{a}\times \vec{b}

To find scalar triple product, first we will find the cross product between two vectors and then do dot product of that result with remaining vector.

Program to calculate triple product of vectors:

program dot
 implicit none
 integer :: v1(3), v2(3), v3(3)	! three vectors v1, v2 and v3 with three components
 integer :: triple_product 		! variable to store final ans
 ! assigning values to vectors
 v1 = (/ 1, 2, 3 /)
 v2 = (/ 4, 5, 6 /)
 v3 = (/ 7, 8, 10 /)
call triple(v1, v2, v3, triple_product)
print*, triple_product
end program

! subroutine to find scalar triple product
subroutine triple(a, b, c, dot)
	implicit none
	 integer :: a(3), b(3),c(3)
	integer ::  cross(3)
	integer :: dot

! calculating cross first between a and b vectors
	cross(1) = a(2)*b(3) - b(2)*a(3)
	cross(2) = b(1)*a(3) - a(1)*b(3)
	cross(3) = a(1)*b(2) - a(2)*b(1)

!	dot = dot_product(c, cross)
	dot = cross(1)*c(1) + cross(2)*c(2) + cross(3)*c(3)
end subroutine

Video to learn in detail

Share this post:

Leave a Comment

Your email address will not be published. Required fields are marked *