FORTRAN 90 Lecturer : Rafel Hekmat Hameed University of Babylon Subject : Fortran 90 College of Engineering Year : Second B.Sc. Mechanical Engiin n e er in g D e p . A APPPPLLIICCA AT TIIO ON NS SA AB BO OU UT TV VE ECCT TO OR RA ALLG GE EB BR RA A A vector V in the plane or in space is an arrow: it is determined by its length, denoted ȁȁ and its direction. We use vectors to represent entities which are described by magnitude and direction. For example, a force applied at a point is a vector: it is completely determined by the magnitude of the force and the direction in which it is applied. An object moving in space has, at any given time, a direction of motion, and a speed. Magnitude of vector Example Calculate the following: following ϭ Sum Example Dot product Angle between two vectors The angle between two nonzero vectors with the same initial point is the smallest angle between them. Example Ϯ Perpendicular vector Example program vector_algbra implicit none real,dimension(3)::v,w,k integer::i real:: sumv,sumw,magn_v,magn_w ,dot_pro, theta data v/5,8,-2/ data w/3,-4,1/ !compute the magnitde of two vectors do i=1,3 sumv=sumv+v(i)**2 sumw=sumw+w(i)**2 enddo magn_v=sqrt(sumv) magn_w=sqrt(sumw) write(*,50)magn_v,magn_w 50 format(2x,"magitude of vector v=",1x,e13.7,/,2x,"magitude of vector w=",1x,e13.7) !calculate the summation tion of two vectors by subroutine program call sum_vectors(v,w,k) write(*,2)(k(i),i=1,3) 2 format(1x,3(2x, f7.4)) !calculate dot product by external function write(*,6) dot_pro(v,w) 6 format(2x,"dot product of two vectors v&w=",f10.6) !angle between two vectors theta=acos(dot_pro(v,w)/(magn_v*magn_w)) ϯ !convert theta to degree theta=theta*180/3.14159 write(*,20)theta 20 format(2x,"angle between two vectors=",f7.3) !check if the two vectors are perpendicular if(dot_pro(v,w)==0)then print*," the two vectors are perpendicular" else print*," the two vectors are not perpendicular" endif end subroutine sum_vectors(v,w,k) implicit none real,dimension(3)::v,w,k integer::i do i=1,3 k(i)=v(i)+w(i) enddo end real function dot_pro(v,w) implicit none real,dimension(3)::v,w real::sum integer::i do i=1,3 sum=sum+v(i)*w(i) enddo dot_pro=sum end ϰ