I would do this via QR decomposition. Produce an orthogonal basis for span 
v1, ..., vn via QR, then see if v changes when you project onto the space 
spanned by the basis. E.g.

V = [v1 v2 ... vn]
(Q,R) = qr(V)

v - Q*(Q'*v) 

That last vector will be zero (small) if v is in span v1, ..., vn.

I like the QR for this because (1) it'll tell you if v1, .. vn are rank 
deficient or approaching rank deficiency (look for small numbers on 
diagonal of R), and also because the Householder reflections in the 
algorithm are unitary and so stable as all get-out. The cols of Q will be 
the best possible calculation of the span of v1 .. vn. Backslash might be 
using LU decomp, which is a less stable algorithm. 

On Wednesday, October 5, 2016 at 12:35:12 PM UTC-4, Abel Siqueira wrote:
>
> If v \in span{v1,...,vn} then Ax = v has a solution, where A = [v1 v2 ... 
> vn].
> An easy way to check it would be
>
> x = A\v
> norm(A*x - v) \approx 0.0
>
> That's not the cheapest way, but it's short.
>
> Abel Soares Siqueira
>
> 2016-10-05 13:00 GMT-03:00 James Noeckel <[email protected] <javascript:>>
> :
>
>> You could iteratively orthogonalize v1 through vn, setting an orthogonal 
>> distance threshold for when to consider a new vector to be in the span of 
>> the previous vectors.
>>
>> On Wednesday, October 5, 2016 at 5:25:26 AM UTC-4, harven wrote:
>>
>>> Is there a way to check if a vector v is in the linear span of a given 
>>> family of vectors v1,...vn?
>>> I don't think I saw such a function in the base library but I may have 
>>> missed it.
>>>
>>> I can use something like 
>>>
>>>  rank([v;v1...vn]) == rank([v1...vn])
>>>
>>> but that looks inefficient. 
>>>
>>> Also is there any facility to compute with matrices with 
>>> integer/rational coefficients?
>>> It seems that the standard library focuses on floats.
>>>
>>
>

Reply via email to