Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Vector Product in Fortran

program vectorcalc

implicit none

real(8) a1,a2,a3,b1,b2,b3,c1,c2,c3
real(8), dimension (:), allocatable :: vectorA(:),vectorB(:),vectorCross(:)
integer dim
real(8) :: dot_product


write(*,*)'enter vectorA,B,Cross dimension'
read(*,*) dim
write(*,*)'entered dimension is', dim

allocate( vectorA (dim))
allocate( vectorB (dim))
allocate( vectorCross(dim))

write(*,*)'enter vectorA values'
read(*,*) a1,a2,a3
write(*,*)'enter vectorB values'
read(*,*) b1,b2,b3

vectorA= (/a1,a2,a3/)
vectorB= (/b1,b2,b3/)

if(dim.eq.3) then 

c1=a2*b3-a3*b2
c2=a3*b1-a1*b3
c3=a1*b2-a2*b1

vectorCross=(/c1,c2,c3/)

    write(*,*) 'a x b:', vectorCross

    write(*,*) 'a*b:', dot_product(vectorA,vectorB)
else 
    write(*,*) 'a*b:', dot_product(vectorA,vectorB)
end if


deallocate (vectorA)
deallocate (vectorB)
deallocate (vectorCross)

end program vectorcalc

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.