Code
program linalg
implicit none
real :: v1(3), v2(3), m(3,3)
integer :: i,j
v1(1) = 0.25
v1(2) = 1.2
v1(3) = 0.2
! use nested do loops to initialise the matrix
! to the unit matrix
do i=1,3
do j=1,3
m(j,i) = 0.0
end do
m(i,i) = 1.0
end do
! do a matrix multiplication of a vector
! equivalent to v2i = mij v1j
do i=1,3
v2(i) = 0.0
do j = 1,3
v2(i) = v2(i) + m(i,j)*v1(j)
end do
end do
write(*,*) ’v2 = ’,v2
end program linalg
Quote
program vector
implicit none
real :: v(3)
real :: x
integer :: i
v(1) = 0.25
v(2) = 1.2
v(3) = 0.2
! compute the modulus squared of the vector
x = 0.0
do i=1,3
x = x + v(i)*v(i)
end do
write(*,*) ’Modulus squared = ’,x
end program vector