Walsh matrix: Difference between revisions
Content deleted Content added
→DOME: Removed an unused line. |
Realize in F# |
||
Line 52:
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// Walsh matrix. Nigel Galloway: August 31st., 2023
open MathNet.Numerics
open MathNet.Numerics.LinearAlgebra
let walsh()=let w2=matrix [[1.0;1.0];[1.0;-1.0]] in Seq.unfold(fun n->Some(n,w2.KroneckerProduct n)) w2
walsh() |> Seq.take 5 |> Seq.iter(fun n->printfn "%s" (n.ToMatrixString()))
</syntaxhighlight>
{{out}}
<pre>
1 1
1 -1
1 1 1 1
1 -1 1 -1
1 1 -1 -1
1 -1 -1 1
1 1 1 1 1 1 1 1
1 -1 1 -1 1 -1 1 -1
1 1 -1 -1 1 1 -1 -1
1 -1 -1 1 1 -1 -1 1
1 1 1 1 -1 -1 -1 -1
1 -1 1 -1 -1 1 -1 1
1 1 -1 -1 -1 -1 1 1
1 -1 -1 1 -1 1 1 -1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1
1 1 -1 -1 1 1 -1 -1 1 1 -1 -1 1 1 -1 -1
1 -1 -1 1 1 -1 -1 1 1 -1 -1 1 1 -1 -1 1
1 1 1 1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1
1 -1 1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1
1 1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 1 1
1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1 1 -1
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1
1 -1 1 -1 -1 1 -1 1 -1 1 -1 1 1 -1 1 -1
1 1 -1 -1 -1 -1 1 1 -1 -1 1 1 1 1 -1 -1
1 -1 -1 1 -1 1 1 -1 -1 1 1 -1 1 -1 -1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 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