i want solve following in least-squares sense:
h = dot(a, b) + dot(a.conj(), c) where complex matrices h, b , c known. remaining complex matrix a (with complex conjugate) being searched.
i tried computing (python) numpy function:
x, res, r, singval = np.linalg.lstsq(np.vstack((b, c)), h) however results not in shape want( --> array((a, a.conj())).
how can solve this?
the easiest way found separating value of a real , imaginary part:
a = u + 1j*v therefore:
h = dot(u, b+c) + 1j*dot(v, b-c) and use of scipy.optimize.lstsqr, model defined as:
def model(b, c, uv): u = uv[:len(uv)//2] v = uv[len(uv)//2:] h = np.dot(u, b+c) + 1j*np.dot(v, b+c) return h.view(float) and residuals as:
def residuals(params, b, c, h): uv = params diff = model(b, c, uv) - h.view(float) return diff.flatten() and result obtained follows:
params, cov = optimize.leastsq(residuals, x0 = np.ones(len(uv), dtype = float), args=(b, c, h))
Comments
Post a Comment