Posts

Showing posts from May, 2021

Gaussian Elimination Method: Fortran f90

 Question: Solve the following system of linear equations using Gaussian Elimination using Fortran. x 1 + x 2 - x 3 + x 4 - x 5 = 2 2x 1 + 2 x 2 + x 3 - x 4 + x 5 = 4 3x 1 + x 2 -3 x 3 -2x 4 + 3 x 5 = 8 4x 1 + x 2 - x 3 +4 x 4 -5x 5 =16 16x 1 -x 2 + x 3 - x 4 - x 5 =32   Solution: program main implicit none integer, parameter :: n=5 double precision:: a(n,n), b(n), x(n) integer:: i,j ! matrix A   data (a(1,i), i=1,5) /  1.0,  1.0,  -1.0, 1.0, -1.0 /   data (a(2,i), i=1,5) /  2.0,  2.0,  1.0, -1.0, 1.0 /   data (a(3,i), i=1,5) /  3.0,  1.0,  -3.0, -2.0, 3.0 /   data (a(4,i), i=1,5) /  4.0,  1.0,  -1.0, 4.0, -5.0 /   data (a(5,i), i=1,5) /  16.0, -1.0, 1.0, -1.0, -1.0 / ! matrix b   data (b(i),   i=1,5) /  2.0, 4.0, 8.0, 16.0, 32.0 / ! print a header and the original equations   write (*,200)   do i=1,n      write ...