mrdivide function in MATLAB: what is it doing, and how can I do it in Python?

前端 未结 4 1970
花落未央
花落未央 2020-12-09 20:11

I have this line of MATLAB code:

a/b

I am using these inputs:

a = [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9]   
b = ones(25, 18)
         


        
4条回答
  •  误落风尘
    2020-12-09 20:42

    TL;DR: A/B = np.linalg.solve(B.conj().T, A.conj().T).conj().T

    I did not find the earlier answers to create a satisfactory substitute, so I dug into Matlab's reference documents for mrdivide further and found the solution. I cannot explain the actual mathematics here or take credit for coming up with the answer. I'm just following Matlab's explanation. Additionally, I wanted to post the actual detail from Matlab to give credit. If it's a copyright issue, someone tell me and I'll remove the actual text.

    %/   Slash or right matrix divide.
    %   A/B is the matrix division of B into A, which is roughly the
    %   same as A*INV(B) , except it is computed in a different way.
    %   More precisely, A/B = (B'\A')'. See MLDIVIDE for details.
    %
    %   C = MRDIVIDE(A,B) is called for the syntax 'A / B' when A or B is an
    %   object.
    %
    %   See also MLDIVIDE, RDIVIDE, LDIVIDE.
    
    %   Copyright 1984-2005 The MathWorks, Inc.
    
    

    Note that the ' symbol indicates the complex conjugate transpose. In python using numpy, that requires .conj().T chained together.

提交回复
热议问题