How do I find values that make up a desired linear combination of vectors?
2 views (last 30 days)
Show older comments
Bello Umar Muhamamd
on 22 Jun 2016
Commented: Dharshini
on 21 Oct 2023
I have 2 vectors A = [2 -1 2 1 0] B = [-1 1 1 0 1]
how can i get the 2 numbers x and y such that x*Ai + y*Bi gives me any vector C such that Ci > 0
1 Comment
Dharshini
on 21 Oct 2023
use Matlab to determine if w=(2,7,-6) is a linerar combination of the vectors v1=(1,2,0), and v2=(0,-1,2).
Accepted Answer
Roger Stafford
on 22 Jun 2016
Edited: Roger Stafford
on 22 Jun 2016
There are infinitely many choices for x and y. Your inequalities can be reduced to:
0 < x < y < 2*x
Any pair of x and y satisfying these will cause C = x*A+y*B > 0.
2 Comments
John D'Errico
on 22 Jun 2016
Simple algebra and some deductive thought will suffice.
A*x + B*y = [2*x - y, y - x, 2*x + y, x, y]
If you know that each of these elements MUST be positive, the you know that both x and y must be positive from the last two cases.
Since y-x must be greater than zero from the second, then you know that
0 < x < y
Since x and y are both forced to be positive, then 2*x+y is trivially positive.
Finally, you are given that 2*x-y>0. Therefore you know that 2*x>y.
So simple deductive reasoning yields the inequality chain:
0 < x < y < 2*x
Any values of x and y that satisfy the above will suffice. Again, there is no presumption that a solution always exists in general.
More Answers (1)
John D'Errico
on 22 Jun 2016
Of course, there is no reason to know that any value of x and y actually exist that will satisfy the requirement. And even if you CAN find such a solution, then it would be of the form C(i) >= 0. Enforcing a strict inequality will be more problematic.
If you just want some solution though, this will suffice:
AB = [A',B']
AB =
2 -1
-1 1
2 1
1 0
0 1
xy = linprog([1 1],-AB,-1.e-8*ones(5,1))
Optimization terminated.
xy =
2.0084e-08
3.0084e-08
A*xy(1) + B*xy(2)
ans =
1.0084e-08 1e-08 7.0253e-08 2.0084e-08 3.0084e-08
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!