CamlFloat Tutorial


Solving Linear Systems

In most numerical problems you will, at some point, need to solve a linear system of the form A x = b. The most straightforward way of doing this is to use the operator /$:
# let sums i j = float_of_int (i+j) ;;
val sums : int -> int -> float = fun

# let a = fun2mat sums 4 4  ;;
   2       3       4       5
   3       4       5       6
   4       5       6       7
   5       6       7       8
val a : Nla.DBlop.matrix = 

# let b = consts 5. 4 1  ;;
   5
   5
   5
   5
val b : Nla.DBlop.matrix = 

# let x = a /$ b  ;;
 1.5
-0.34
-8.8
 7.7
val x : Nla.DBlop.matrix = 
Now you can calculate a *$ x to check the result.

Non-square matrices

For fat or skinny matrices, the /$ operator acts appropriately: for skinny matrices it produces the least-squares solution and for fat matrices it returns the minimum norm solution.

::: back :::