对于给定的向量,我想找到它周围的正交基, 即给定矢量归一化和随机选择的正交子空间的基础。 朱莉娅有这个方便的功能吗?
答案 0 :(得分:8)
你可以定义一个函数orth(如果有人还没有这样做)
orth(M) = qr(M)[1]
见这里: https://groups.google.com/forum/#!topic/julia-users/eG6a4tj7LGg和http://docs.julialang.org/en/release-0.4/stdlib/linalg/
或者来自IterativeSolvers.jl:
orthogonalize{T}(v::Vector{T}, K::KrylovSubspace{T})
答案 1 :(得分:4)
您正在寻找的功能称为nullspace
。
julia> x = randn(5);
julia> x⊥ = nullspace(x');
julia> x'x⊥
1×4 Array{Float64,2}:
7.69373e-16 -5.45785e-16 -4.27252e-17 1.26778e-16
答案 2 :(得分:2)
以下将计算矩阵M
的正交基function orth(M::Matrix)
matrixRank = rank(M)
Ufactor = svdfact(M)[:U]
return Ufactor[:,1:matrixRank]
end
使用julia文档:
"""
orth(M)
Compute an orthogonal basis for matrix `A`.
Returns a matrix whose columns are the orthogonal vectors that constitute a basis for the range of A.
If the matrix is square/invertible, returns the `U` factor of `svdfact(A)`, otherwise the first *r* columns of U, where *r* is the rank of the matrix.
# Examples
```julia
julia> orth([1 8 12; 5 0 7])
2×2 Array{Float64,2}:
-0.895625 -0.44481
-0.44481 0.895625
```
```
julia> orth([1 8 12; 5 0 7 ; 6 4 1])
3×3 Array{Float64,2}:
-0.856421 0.468442 0.217036
-0.439069 -0.439714 -0.783498
-0.27159 -0.766298 0.582259
```
"""
function orth(M::Matrix)
matrixRank = rank(M)
Ufactor = svdfact(M)[:U]
return Ufactor[:,1:matrixRank]
end