线性代数,有没有一个函数能找到所有与给定向量正交的向量



对于一个给定的向量,我想找到它周围的正交基,即给定的正交子空间的归一化和随机选择的基。在Julia中有方便的函数吗?

您正在查找的函数名为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

你可以定义一个函数值(如果有人还没有这样做的话)

orth(M) = qr(M)[1]

看这里:https://groups.google.com/forum/!topic/julia-users/eG6a4tj7LGg and http://docs.julialang.org/en/release-0.4/stdlib/linalg/

或者来自IterativeSolvers.jl:

orthogonalize{T}(v::Vector{T}, K::KrylovSubspace{T})

看:https://github.com/JuliaMath/IterativeSolvers.jl

下面将计算矩阵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

相关内容

  • 没有找到相关文章

最新更新