Version 2 of Simultaneous Equations

Updated 2006-10-21 23:50:44

Example of use of the math::linearalgebra package to solve a question posed on [L1 ]

This text copied directly from the above reference:

  Example:
  A man buys 3 fish and 2 chips for £2.80
  A woman buys 1 fish and 4 chips for £2.60
  How much are the fish and how much are the chips?

Use the linear algebra package thus:

  package require math::linearalgebra
  set mt [math::linearalgebra::mkMatrix 2 2 0.0]  ;# there are 2 transactions buying 2 items
  set vc [math::linearalgebra::mkVector 2 0.]     ;# 2 transactions
  math::linearalgebra::setelem mt 0  0 3          ;# 3 fish in transaction 1...
  math::linearalgebra::setelem mt 0  1 2          ;# 2 chips
  math::linearalgebra::setelem mt 1  0 1          ;# 1 fish in transaction 2
  math::linearalgebra::setelem mt 1  1 4          ;# 4 chips (this is a rather unbalanced meal)
  math::linearalgebra::setelem vc 0 2.8           ;# cost of transaction 1
  math::linearalgebra::setelem vc 1 2.6           ;# and transaction 2
  math::linearalgebra::solveGauss $mt $vc         ;# calcualte the result

And the result:

  0.6 0.500000000001

or the fish cost 0.60 (rather cheap) and the chips 0.50. As given in the reference above.


Category Mathematics