1

I have a set of 3 complex vectors, I want to a find a linear combination of these vectors that would amount to an offset (y = c) - like an array with all elements equal to each other, within a tolerance.

find a, b, and c such that

a*vectors[0] + b*vectors[1] + c*vectors[2] 

is equal to

np.ones_like(vectors[0])*R 

where R is some complex scalar.

And then I need to repeat this, but with the constraint being a tilt instead of an offset (y = mx)

I have been staring in despair at scipy.optimize functions but have no idea where to begin. I thought I could use curve_fit where X is my vectors array, and Y is the offset, but R could be anything. I have looked at a lot of questions on this website about finding linear combination of vectors to get a set target, all involving least squares algorithms and regression, but in these questions, the target is always very clearly set, and mine is not.

Any help would be appreciated.

If it helps, here is the vector array:

vectors = [[-0.05595785+0.j         -0.02067704+0.96237886j  0.01788292+0.91801663j
  0.01638632+0.89043662j -0.00940294+0.86416253j -0.04124763+0.84856943j
 -0.07209872+0.84014654j -0.09694049+0.84415515j -0.11041203+0.87747744j
 -0.11280149+0.90039313j -0.11049056+0.91109975j -0.11048226+0.90795703j
 -0.11858175+0.90167201j -0.12435044+0.91616836j -0.13327415+0.92503116j
 -0.15029659+0.92995771j -0.18068274+0.93675527j -0.219918  +0.96426471j
 -0.23302548+1.03547945j -0.20804073+1.10629325j -0.16236329+1.1410909j
 -0.1395226 +1.14736029j -0.13274937+1.17171783j -0.08154881+1.21819715j
 -0.01260256+1.22220135j  0.02440899+1.19255107j  0.03181309+1.17177358j
  0.04052842+1.16086606j  0.06229635+1.15418931j  0.07827962+0.j        ]
[ 0.13960754+0.j          0.15883152+0.61495684j  0.29275993+0.7951821j
  0.50531005+0.92696802j  0.74459812+0.94749429j  0.94302144+0.85065558j
  1.03815336+0.69669179j  1.05760245+0.56690778j  1.08602193+0.47764643j
  1.0860309 +0.38319665j  1.04421356+0.31078688j  0.99800496+0.28223413j
  0.97584298+0.26824647j  0.98367673+0.25180156j  1.00149139+0.24309192j
  1.04185799+0.2276887j   1.10064048+0.18885346j  1.17160345+0.10190804j
  1.22166034-0.06962931j  1.16705674-0.26264473j  1.02869959-0.385853j
  0.89500481-0.41972091j  0.80761405-0.43157533j  0.71985933-0.47264141j
  0.60330173-0.47872411j  0.51106118-0.42849817j  0.47229649-0.36894518j
  0.45982437-0.33598009j  0.44241121-0.33143811j  0.4125255 +0.j        ]
[-1.34717439+0.j         -1.85723443-0.63216626j -2.14169716-0.06585348j
 -2.08677468+0.54603237j -1.71793861+0.96084092j -1.26443764+1.11681916j
 -0.85229978+1.08715208j -0.53386952+0.94652411j -0.33258462+0.78905829j
 -0.19739978+0.62879446j -0.10777746+0.4756731j  -0.05964638+0.33944905j
 -0.04163412+0.23675148j -0.0319222 +0.18115283j  0.00295115+0.16393733j
  0.09306699+0.14214935j  0.20598206+0.06257386j  0.29090676-0.06831863j
  0.33007931-0.24142598j  0.28082543-0.42363605j  0.15973201-0.53559239j
  0.05068626-0.57177554j -0.03386762-0.59290642j -0.139633  -0.605745j
 -0.24763383-0.57102344j -0.32101282-0.49963981j -0.36026907-0.42238967j
 -0.3792613 -0.34209787j -0.379106  -0.25523545j -0.34043382+0.j        ]]
3
  • In the 'tilt' case, can you explain in more detail what y, m and x are? Commented Apr 9 at 11:30
  • Is complex scalar R known? It seems that it isn't; do you know of any bounds? Commented Apr 9 at 11:30
  • For the first case, there's nothing stopping a naive linear solver from saying a=0, b=0, c=0, R=0. You need to explain more constraints showing that that isn't a solution. Commented Apr 9 at 11:41

1 Answer 1

0

Written naively, your first problem looks like

import numpy as np


vectors = np.array([
    [
        0.05595785+0.j        , -0.02067704+0.96237886j,  0.01788292+0.91801663j,
        0.01638632+0.89043662j, -0.00940294+0.86416253j, -0.04124763+0.84856943j,
        0.07209872+0.84014654j, -0.09694049+0.84415515j, -0.11041203+0.87747744j,
        0.11280149+0.90039313j, -0.11049056+0.91109975j, -0.11048226+0.90795703j,
        0.11858175+0.90167201j, -0.12435044+0.91616836j, -0.13327415+0.92503116j,
        0.15029659+0.92995771j, -0.18068274+0.93675527j, -0.219918  +0.96426471j,
        0.23302548+1.03547945j, -0.20804073+1.10629325j, -0.16236329+1.1410909j ,
        0.1395226 +1.14736029j, -0.13274937+1.17171783j, -0.08154881+1.21819715j,
        0.01260256+1.22220135j,  0.02440899+1.19255107j,  0.03181309+1.17177358j,
        0.04052842+1.16086606j,  0.06229635+1.15418931j,  0.07827962+0.j        ,
    ],
    [
        0.13960754+0.j        ,  0.15883152+0.61495684j,  0.29275993+0.7951821j ,
        0.50531005+0.92696802j,  0.74459812+0.94749429j,  0.94302144+0.85065558j,
        1.03815336+0.69669179j,  1.05760245+0.56690778j,  1.08602193+0.47764643j,
        1.0860309 +0.38319665j,  1.04421356+0.31078688j,  0.99800496+0.28223413j,
        0.97584298+0.26824647j,  0.98367673+0.25180156j,  1.00149139+0.24309192j,
        1.04185799+0.2276887j ,  1.10064048+0.18885346j,  1.17160345+0.10190804j,
        1.22166034-0.06962931j,  1.16705674-0.26264473j,  1.02869959-0.385853j  ,
        0.89500481-0.41972091j,  0.80761405-0.43157533j,  0.71985933-0.47264141j,
        0.60330173-0.47872411j,  0.51106118-0.42849817j,  0.47229649-0.36894518j,
        0.45982437-0.33598009j,  0.44241121-0.33143811j,  0.4125255 +0.j        ,
    ],
    [
        -1.34717439+0.j        , -1.85723443-0.63216626j, -2.14169716-0.06585348j,
        -2.08677468+0.54603237j, -1.71793861+0.96084092j, -1.26443764+1.11681916j,
        -0.85229978+1.08715208j, -0.53386952+0.94652411j, -0.33258462+0.78905829j,
        -0.19739978+0.62879446j, -0.10777746+0.4756731j , -0.05964638+0.33944905j,
        -0.04163412+0.23675148j, -0.0319222 +0.18115283j,  0.00295115+0.16393733j,
         0.09306699+0.14214935j,  0.20598206+0.06257386j,  0.29090676-0.06831863j,
         0.33007931-0.24142598j,  0.28082543-0.42363605j,  0.15973201-0.53559239j,
         0.05068626-0.57177554j, -0.03386762-0.59290642j, -0.139633  -0.605745j  ,
        -0.24763383-0.57102344j, -0.32101282-0.49963981j, -0.36026907-0.42238967j,
        -0.3792613 -0.34209787j, -0.379106  -0.25523545j, -0.34043382+0.j        ,
    ],
])

# Vectors is (3, 30); convert it to homogeneous (30, 4)
# av0 + bv1 + cv2 = R
# [v0 v1 b2 -1] @ [a b c R] = 0
homogeneous = np.vstack((
    vectors,
    np.full_like(vectors[0], fill_value=-1),
)).T

(a, b, c, R), residuals, rank, singular = np.linalg.lstsq(
    a=homogeneous, b=np.zeros_like(vectors[0]),
)

This "succeeds" and produces a=0, b=0, c=0, R=0; which really is a solution. If it isn't one you like, you need to choose some more constraints and use a different method; or scale the entire system for R:

# a/R*v0 + b/R*v1 + c/R*v2 = 1
(a, b, c), residuals, rank, singular = np.linalg.lstsq(
    a=vectors.T, b=np.ones_like(vectors[0]),
)

print(a)
print(b)
print(c)
(-0.002558995337825785-0.4153223431626433j)
(0.5507299146223893+0.0009271169427349513j)
(-0.2945381908343979+0.14446580277473847j)

In this form R is a fully-free parameter. With no other information it's fully wild guessing what a reasonable value would be; perhaps a scale for abc to be unitary:

# a/R*v0 + b/R*v1 + c/R*v2 = 1
abcR, residuals, rank, singular = np.linalg.lstsq(
    a=vectors.T, b=np.ones_like(vectors[0]),
)

# e.g. force abc to be unitary
R = 1/np.linalg.norm(abcR)
abc = abcR*R

print('abc =', abc)
print('R =', R)
abc = [-0.00335024-0.54374112j  0.72101708+0.00121378j -0.38561019+0.18913502j]
R = 1.3092026733974018

or perhaps a complex scalar to rotate the system so that b == 1:

R = 1/abcR[1]
abc = abcR*R

print('abc =', abc.round(18))
print('R =', R)
abc = [-0.00591606-0.75412075j  1.        -0.j         -0.53437111+0.26321655j]
R = (1.815766929506332-0.0030567220695781367j)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.