QR decomposition: Difference between revisions
m
→{{header|Standard ML}}
Line 2,667:
=={{header|Standard ML}}==
{{trans|Axiom}}
We first define a signature for a radical category joined with a field. We then define a functor with (a) structures to define operators and functions for Array and Array2, and (b) functions for the QR decomposition
<lang sml>signature RADCATFIELD = sig
type real
Line 2,676 ⟶ 2,677:
val * : real * real -> real
val / : real * real -> real
val sign : real -> real
val sqrt : real -> real
Line 2,731:
fun updateSubMatrix(h,i,j,s) =
tabulate RowMajor (nRows s, nCols s, fn (a,b) => update(h,Int.+(i,a),Int.+(j,b),sub(s,a,b)))
fun print a =▼
end
end
List.tabulate(Array2.nRows a, fn i => List.tabulate(Array2.nCols a, fn j => Array2.sub(a,i,j)))
fun householder a =
let open Array
Line 2,815 ⟶ 2,803:
end
structure Q = QR(
let
Line 2,821 ⟶ 2,809:
val {q,r} = Q.qr(mat)
in
end;
(* output *)
val it =
[0.285714285714,~0.171428571429,0.942857142857]],
let open Array
|