Solve:

**Eliminate***x*_{1}from both equations by making the coefficients of*x*_{1}in each the same and subtracting:- divide first equation by 4
x _{1}+ 0.5 x_{2}= 0.25 - subtract
(1-1) x _{1}+ (-4 - 0.5) x_{2}= (5-0.25) - leaving a single equation in x
_{2}-4.5 x _{2}= 4.75 - Hence x
_{2}

*x*_{2}= -1.055556

- divide first equation by 4
- Now
**substitute**x_{2}**back**into the first equation as reduced in the first step of 1. above, i.e.:

*x*_{1}+ 0.5 (-1.055556) = 0.25This is in a convenient form for obtaining x

_{1}:

*x*_{1}= 0.25 + 0.5 (1.055556) = 0.77778

In symbols:

Eliminate x_{1}

- by dividing first equation by a
_{1,1}and and keep this modified equation for future use:

x _{1}+ a_{1,2}/ a_{1,1}x_{2}= b_{1}/ a_{1,1} - multiply by a
_{2,1}, giving both equations same x_{1}coefficient:

- Subtract giving single equation:

- Hence x
_{2}:

- Back substitute in `saved' equation to get x
_{1}.

The equation, now rearranged for x_{1}is:

x

Substituting:

Set of *n* equations

(1) |

This may be written in matrix-vector form:

!Start the elimination loop..... do i=1,n-1 !... go down the matrix by rows i... !.. reducing all the other rows k.. do k=i+1,n pivot=(a(k,i)/a(i,i)) !This is the number to multiply each !row of equn i by before subtracting it.. !.. along each row k .. do j=1,n a(k,j)=a(k,j)-pivot*a(i,j) end do ! .. and also the constant. b(k)=b(k)-pivot*b(i) ! end do !.. go on to next row with current elimination !end do !.. and then eliminate next equation ! !.. and finally solve the one remaining !equation for x(n) x(n)=b(n)/a(n,n) !--- Elimination Complete --------- !Back substitute for other x() ... do l=n-1,1,-1 x(l)=b(l) do j=l+1,n x(l)=x(l)-a(l,j)*x(j) end do x(l)=x(l)/a(l,l) end do !----- Finished ------------

program lintest implicit none !test linear solver integer :: n,i,j,ifg integer, parameter :: max=50 real :: a(max,max),x(max),c(max) print *, 'Solver for small sets of linear equations...' print *, 'Enter number of equations, less than ',max read *, n print *, 'Now enter coefficients ...' print *, 'i.e. ',n+1, ' numbers per row...' do i=1,n print *, 'Elements for row ', i, ':' read *, (a(i,j), j=1,n), c(i) end do ....... print *, 'Matrix and constants are:' do i=1,n !check print write(6,'(7f10.4)') (a(i,j),j=1,n), c(i) end do call solve_linear (a,max,x,n,c,ifg) write(6,*) 'flag =',ifg write(6,*) 'solution..' write(6,*) (x(i),i=1,n) end program

Next - Section 3.6.2: Example Questions

Return to Section 3 Index