Matrix Division - how does it work?

413 vues (au cours des 30 derniers jours)
David
David le 1 Mar 2011
Commenté : Ahmed Inirat le 5 Déc 2021
Hi there,
I'm new to matlab and just attempting to get my head around how matrix \ vector division works.
Below is an example.
Assume we have :-
A = [a1 a2]; B = [b1 b2]; C = [c1 c2];
X = [x1 x2]; Y = [y1 y2]; Z = [z1 z2];
m1 = [A B C; 1 1 1]; m2 = [X Y Z; 1 1 1];
result = (m1 / m2);
The part I'm trying to break down is the actual division i.e. m1 / m2.
This breaks down as follows :-
m1 / m2;
[A B C; 1 1 1] / [X Y Z; 1 1 1];
[[a1 a2] [b1 b2] [c1 c2]; 1 1 1] / [[x1 x2] [y1 y2] [z1 z2]; 1 1 1];
So what I'm trying to understand is what is actually going on in the division here :-
[[a1 a2] [b1 b2] [c1 c2]; 1 1 1] / [[x1 x2] [y1 y2] [z1 z2]; 1 1 1]
I'm trying to break that division down into its constituent parts, piece by piece... this is the bit I'm struggling with.. Any help appreciated..
Many thanks, David
  1 commentaire
Prasad Jadhav
Prasad Jadhav le 17 Oct 2019
how to make 14*14 matrix in matlab

Connectez-vous pour commenter.

Réponses (5)

Matt Tearle
Matt Tearle le 1 Mar 2011
Your example doesn't work, using standard MATLAB syntax, because A, B, and C would be row vectors (1-by-2), so [A B C] would be a 1-by-6 row vector, which you can't concatenate vertically with [1 1 1].
Anyway, the best way to think about all matrix division is in terms of solving linear systems. MATLAB interprets
>> x = A/B
as "solve the linear system x*B = A (for x)". And, similarly,
>> x = A\B
is "solve the linear system A*x = B (for x)". MATLAB will solve the system if at all possible (ie if the dimensions are consistent), giving, in general, the least-squares solution (ie minimizing the 2-norm of the residual). This means it will "solve" over/under/determined systems, in the most natural way possible -- the actual solution if there is one, or the least-squares solution otherwise.
  2 commentaires
Diamant Sopi
Diamant Sopi le 26 Fév 2021
Hi, can you tell me please how can i calculate this in Matlab?
Ahmed Inirat
Ahmed Inirat le 5 Déc 2021
[1, 5; 0, 1]\[46; 16]

Connectez-vous pour commenter.


Paulo Silva
Paulo Silva le 1 Mar 2011
The documentation is very good in that part
doc mldivide
If you have the symbolic toolbox
syms a b c d e f g h
m1=[a b
c d];
m2=[e f
g h];
m1/m2
This gives
ans=
[ (a*h - b*g)/(e*h - f*g), -(a*f - b*e)/(e*h - f*g)]
[ (c*h - d*g)/(e*h - f*g), -(c*f - d*e)/(e*h - f*g)]
Your example won't work because the matrix isn't well constructed, please fix it.
Maybe you want to do this:
syms a1 a2 b1 b2 c1 c2 x1 x2 y1 y2 z1 z2
[[a1 a2];[b1 b2];[c1 c2]] / [[x1 x2];[y1 y2];[z1 z2]]
The solution isn't unique
ans =
[ (y1*(a1*x2 - a2*x1) + a1*(x1*y2 - x2*y1))/(x1*(x1*y2 - x2*y1)), -(a1*x2 - a2*x1)/(x1*y2 - x2*y1), 0]
[ (y1*(b1*x2 - b2*x1) + b1*(x1*y2 - x2*y1))/(x1*(x1*y2 - x2*y1)), -(b1*x2 - b2*x1)/(x1*y2 - x2*y1), 0]
[ (y1*(c1*x2 - c2*x1) + c1*(x1*y2 - x2*y1))/(x1*(x1*y2 - x2*y1)), -(c1*x2 - c2*x1)/(x1*y2 - x2*y1), 0]

David
David le 2 Mar 2011
Hi there,
Thanks for your answers.
If I change to the following, does that then become valid in Matlab?
a = 2; b = 3; c = 4;
m1 = [a b c; 1 1 1];
x = 5; y = 6; z = 7;
m2 = [x y z; 1 1 1];
m1 / m2 = [a b c; 1 1 1] / [x y z; 1 1 1];
And if valid, how would [a b c; 1 1 1] / [x y z; 1 1 1] break down?
Unfortunately I dont have the Symbolic Toolbox so cant test that.
Thanks again,
David

Paulo Silva
Paulo Silva le 2 Mar 2011
syms a b c x y z
[a b c; 1 1 1] / [x y z; 1 1 1];
ans =
[ Inf, Inf]
[ 0, 1]
syms a b c d
[a b; 1 1] / [c d; 1 1]
ans =
[ (a - b)/(c - d), -(a*d - b*c)/(c - d)]
[ 0, 1]

Matt Tearle
Matt Tearle le 2 Mar 2011
Yes, what you have is valid MATLAB, but what do you mean about how it would break down? This seems more like a question of linear algebra than MATLAB. And is there any reason you're particularly interested in that specific structure?
As I said above, MATLAB will calculate m1/m2 by solving the system Something*m2 = m1. In order for the matrix dimensions to work, Something needs to be 2-by-2. So:
[P Q][x y z] = [a b c]
[R S][1 1 1] [1 1 1]
which translates into 6 equations:
Px + Q = a
Py + Q = b
Pz + Q = c
Rx + S = 1
Ry + S = 1
Rz + S = 1
From the last 3 we see that R must be zero, and therefore S = 1, unless x=y=z. In that latter case, there is no solution unless a=b=c also. Then there are infinitely many solutions, including R=0 & S=1. So let's assume those values, either way.
That leaves us with 3 equations for the 2 unknowns P & Q. It will therefore depend on the choice of a, b, and c as to whether this has a solution. If there isn't one, MATLAB will return the least-squares best fit. If there is a solution, Q = (a-b)/(x-y) = (a-c)/(x-z) = (b-c)/(y-z). So these things all being equal is a condition on whether there's a solution. (Or, if any of x, y, and z are equal, then the corresponding a, b, and c must also be equal.) P, then, is easily calculated: P = a - Qx = b - Qy = c - Qz.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by