In today’s lesson, we learn how to compute a vector cross product using Fortran.
function cross(a,b) result(axb)
implicit none
integer,parameter :: wp=selected_real_kind(15, 307) !double precision
real(wp),dimension(3) :: axb
real(wp),dimension(3),intent(in) :: a
real(wp),dimension(3),intent(in) :: b
axb(1) = a(2)*b(3) - a(3)*b(2)
axb(2) = a(3)*b(1) - a(1)*b(3)
axb(3) = a(1)*b(2) - a(2)*b(1)
end function cross