How to find inverse of a non square matrix?

6 views (last 30 days)
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.

Accepted Answer

Matt J
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
Muneeb Aizaz
Muneeb Aizaz on 25 Sep 2018
so this is satisfying the conditions that a1+a2=1 and a1 and a2>0 ?
Bruno Luong
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.

Sign in to comment.

More Answers (2)

Bruno Luong
Bruno Luong on 25 Sep 2018
Edited: Bruno Luong on 25 Sep 2018
unconstrained solution
a = y \ x
  3 Comments
Bruno Luong
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
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;

Sign in to comment.


KSSV
KSSV on 25 Sep 2018
Edited: KSSV on 25 Sep 2018
x = rand(91,1) ;
y = rand(91,2) ;
a = y\x
  1 Comment
Muneeb Aizaz
Muneeb Aizaz on 25 Sep 2018
Sorry there is one additional condition that the values a1 and a2 should sum upto 1.

Sign in to comment.

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!