Singular value decomposition: Difference between revisions

Content added Content deleted
(Initialize)
 
mNo edit summary
Line 42: Line 42:


The output may vary depending your choice of the data types.
The output may vary depending your choice of the data types.


=={{header|Julia}}==
Julia has an svd() function as part of its built-in LinearAlgebra package.
<syntaxhighlight lang="julia">
julia> using LinearAlgebra

julia> function testsvd()
rows, cols = [parse(Int, s) for s in split(readline())]
arr = zeros(rows, cols)
for row in 1:rows
arr[row, :] .= [tryparse(Float64, s) for s in split(readline())]
end
display(svd(arr))
end
testsvd (generic function with 1 method)

julia> testsvd()
2 2
3 0
4.5
SVD{Float64, Float64, Matrix{Float64}, Vector{Float64}}
U factor:
2×2 Matrix{Float64}:
-0.346946 -0.937885
-0.937885 0.346946
singular values:
2-element Vector{Float64}:
6.74492216626026
2.0015056760076915
Vt factor:
2×2 Matrix{Float64}:
-0.780042 -0.625727
-0.625727 0.780042

</syntaxhighlight>