How to find inverse of a non square matrix?
6 views (last 30 days)
Show older comments
Hello I have some a (91x1) array x and (91x2) array y. i need to find two constants a1, a2 which basically make a (2x1) array.
my equation is x=y*a , where a is the 2x1 matrix. my matrix dimensions match but i am unsure how to solve this equation for the values of a1 and a2.
Edited: additional condition is that the values a1 and a2 should sum to 1. it can be assumed that y has values greater y. Any help will be appreciated.
0 Comments
Accepted Answer
Matt J
on 25 Sep 2018
Edited: Matt J
on 25 Sep 2018
Although it may be overkill for such a small problem, you could also use lsqlin,
a = lsqlin(y,x,[],[], [1,1],1 ,[0,0],[1,1]);
2 Comments
Bruno Luong
on 25 Sep 2018
Almost a1 and a2 >= 0 (not strictly positive), if you like to use a big hammer. Otherwise look at the solution I propose above.
More Answers (2)
Bruno Luong
on 25 Sep 2018
Edited: Bruno Luong
on 25 Sep 2018
unconstrained solution
a = y \ x
3 Comments
Bruno Luong
on 25 Sep 2018
Edited: Bruno Luong
on 25 Sep 2018
constraints a1+a2 = 1
a2 = diff(y,1,2)\(x-y(:,1));
a1 = 1-a2;
Bruno Luong
on 25 Sep 2018
Edited: Bruno Luong
on 25 Sep 2018
constraints a1+a2 = 1, and a1, a2 >= 0
a2 = diff(y,1,2)\(x-y(:,1));
a2 = min(max(a2,0),1);
a1 = 1-a2;
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!