Chapter 2

j_02_01.jl

Gaussian Elimination for linear simultaneous equations.

Other versions: p_02_01.jl, nm21.f95


In [21]:
using NMfE

Gaussian elimination of an equation like:

$[\mathbf{A}]\{\mathbf{x}\}=\{\mathbf{b}\}$

First define matrix A and right hand side vector b:


In [22]:
A=[10. 1. -5.;-20. 3. 20.;5. 3. 5.]


Out[22]:
3x3 Array{Float64,2}:
  10.0  1.0  -5.0
 -20.0  3.0  20.0
   5.0  3.0   5.0

In [23]:
b=[1., 2., 6.]


Out[23]:
3-element Array{Float64,1}:
 1.0
 2.0
 6.0

In [32]:
c = A\b


Out[32]:
3-element Array{Float64,1}:
  1.0
 -2.0
  1.4

In [33]:
round(A * c, 14) == b


Out[33]:
true