0% found this document useful (0 votes)
637 views3 pages

A Fortran 90 Program To Solve A Set of Linear Equations by Using

This document discusses solving systems of linear equations using inverse matrices. It provides an example of solving the equations X1 + X2 -3X3 = 9, -X1 + 2X2 = 6, X1 - X2 +X3 = -5. It also includes a Fortran 90 program to calculate the inverse matrix and solve a set of linear equations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
637 views3 pages

A Fortran 90 Program To Solve A Set of Linear Equations by Using

This document discusses solving systems of linear equations using inverse matrices. It provides an example of solving the equations X1 + X2 -3X3 = 9, -X1 + 2X2 = 6, X1 - X2 +X3 = -5. It also includes a Fortran 90 program to calculate the inverse matrix and solve a set of linear equations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

FORTRAN 90

Lecturer : Rafel Hekmat Hameed University of Babylon

Subject : Fortran 90 College of Engineering

Year : Second B.Sc. Mechanical Engineering Dep.

SSoolluuttiioonn aa sseett ooff lliinneeaarr eeqquuaattiioonnss bbyy


IInnvveerrssee MMaattrriixx
One of the most important applications of matrices is to the solution of linear
simultaneous equations.

Given
AX = B
We can multiply both sides by the inverse of A, provided this exists, to give
A−1AX = A−1B
But A−1A = I, the identity matrix. Furthermore, IX = X, because multiplying any
matrix by an identity matrix of the appropriate size leaves the matrix unaltered. So
X = A−1B
This result gives us a method for solving simultaneous equations. All we
need do is write them in matrix form, calculate the inverse of the matrix of
coefficients, and finally perform a matrix multiplication.

Example
Solve the simultaneous equations
X1 + X2 -3X3 = 9
-X1 + 2X2 = 6
X1 - X2 +X3 = -5

Provided you understand how matrices are multiplied together you will
realize that these can be written in matrix form as

ͳ ͳ െ͵ ‫ݔ‬ଵ ͻ
൥െͳ ʹ Ͳ ൩ ൥ ‫ݔ‬ଶ ൩ ൌ ൥ ͸൩
ͳ െͳ ͳ ‫ݔ‬ଷ െͷ
ϭ
We need to calculate the inverse of A

ͳȀ͵ ͳȀ͵ ͳ
-1
A =൥ ͳȀ͸ ʹȀ͵ ͳȀʹ൩
െͳȀ͸ ͳȀ͵ ͳȀʹ

Then X is given by X = A−1B

ͳȀ͵ ͳȀ͵ ͳ ͻ
=൥ ͳȀ͸ ʹȀ͵ ͳȀʹ൩ ቈ ͸ ቉
െͳȀ͸ ͳȀ͵ ͳȀʹ െͷ
Ͳ
=൥ ͵ ൩
െʹ

Hence X1= 0 , X2 =3 and X3= -2 is the solution of the simultaneous equations.

A Fortran 90 program to solve a set of linear equations by using


INVERSE MATRIX

program solve_equations_by_inverse_matrix
implicit none
integer,parameter::n=3
real,dimension (n)::b,x
real,dimension(n,n)::a,a1
integer::i,j,k,l
real::z
data a/1,-1,1,1,2,-1,-3,0,1/
data a1/1,3*0,1,3*0,1/
data b/9,6,-5/

!divided all elements of a & a1 by a(i,i)


do i=1,n
z=a(i,i)
do j=1,n
a(i,j)=a(i,j)/z
a1(i,j)=a1(i,j)/z
enddo

!make zero all entries in column a(j,i) & a1(j,i)


do j=i+1,n
z=a(j,i)
do k=1,n
a(j,k)=a(j,k)-z*a(i,k)
Ϯ
a1(j,k)=a1(j,k)-z*a1(i,k)
enddo
enddo ; enddo

!subtract appropiate multiple of row j from j-1


do i=1,n-1
do j=i+1,n
z=a(i,j)
do l=1,n
a(i,l)=a(i,l)-z*a(j,l)
a1(i,l)=a1(i,l)-z*a1(j,l)
enddo
enddo
enddo

do i=1,n
write(*,60)(a(i,j),j=1,n) , (a1(i,j),j=1,n)
60 format(2x,3(f10.6),10x,3(f10.6))
enddo
print*,"********************"

CALL MULTI (a1,b,x)


do i=1,n
print 10,"x",i,"=",x(i)
enddo
10 format(2x,a,i1,a,f10.5)
end

subroutine multi(a1,b,x)
implicit none
integer,parameter::n=3
real,dimension (n)::b,x
real,dimension(n,n)::a1
integer::i,j,k
do i=1,n
do j=1,n
x(i)=0
do k=1,n
x(i)=x(i)+a1(i,k)*b(k)
enddo;enddo;enddo
end

You might also like