Gaussian elimination: Difference between revisions

Realize in F#
(Added a Modula-3 implementation)
(Realize in F#)
Line 765:
<pre>1.00, 0.00, 0.00, 4.00</pre>
 
=={{header|F_Sharp|F#}}==
===The Function===
<lang fsharp>
// Gaussian Elimination. Nigel Galloway: February 2nd., 2019
let gelim augM=
let f=List.length augM
let fG n (g:bigint list) t=n|>List.map(fun n->List.map2(fun n g->g-n)(List.map(fun n->n*g.[t])n)(List.map(fun g->g*n.[t])g))
let rec fN i (g::e as l)=
match i with i when i=f->l|>List.mapi(fun n (g:bigint list)->(g.[f],g.[n]))
|_->fN (i+1) (fG e g i@[g])
fN 0 augM
</lang>
===The Task===
This task uses functionality from [[Continued_fraction/Arithmetic/Construct_from_rational_number#F.23]] and [[Continued_fraction#F.23]]
<lang fsharp>
let test=[[ -6I; -18I; 13I; 6I; -6I; -15I; -2I; -9I; -231I];
[ 2I; 20I; 9I; 2I; 16I; -12I; -18I; -5I; 647I];
[ 23I; 18I; -14I; -14I; -1I; 16I; 25I; -17I; -907I];
[ -8I; -1I; -19I; 4I; 3I; -14I; 23I; 8I; 248I];
[ 25I; 20I; -6I; 15I; 0I; -10I; 9I; 17I; 1316I];
[-13I; -1I; 3I; 5I; -2I; 17I; 14I; -12I; -1080I];
[ 19I; 24I; -21I; -5I; -19I; 0I; -24I; -17I; 1006I];
[ 20I; -3I; -14I; -16I; -23I; -25I; -15I; 20I; 1496I]]
let fN (n,g)=cN2S(π(rI2cf n g))
gelim test |> List.map fN |> List.iteri(fun i n->(printfn "x[%d]=%1.14f " (i+1) (snd (Seq.pairwise n|> Seq.find(fun (n,g)->n-g < 0.0000000000001M)))))
</lang>
{{out}}
<pre>
x[1]=12.00000000000000
x[2]=10.00000000000000
x[3]=-20.00000000000000
x[4]=22.00000000000000
x[5]=-1.00000000000000
x[6]=-20.00000000000000
x[7]=-25.00000000000000
x[8]=23.00000000000000
</pre>
=={{header|Fortran}}==
Gaussian Elimination with partial pivoting using augmented matrix
Line 812 ⟶ 849:
end program
</lang>
 
=={{header|FreeBASIC}}==
Gaussian elimination with pivoting.
2,172

edits