How do i solve this block matrix equation using MATLAB ?

I have this equation
[A B;C 0]*[G;H]=[G*Am;Cm]
which is needed to be solved for G and H , this equation can be written as
[G;H]=[A B;C 0]*inv([A B;C 0]*[A B;C 0]')*[G*Am;Cm]
and the matrices are given as
A=[0 1;1 -2],B=[0;1],C=[1 0],Am=[0 1;-1 0],Cm=[1 0.5]
dimension of G should be 2X2 and H 1X2
How to write a code to solve for G and H ?

 Accepted Answer

A=[0 1;1 -2]; B=[0;1]; C=[1 0]; Am=[0 1;-1 0]; Cm=[1 0.5];
G = sym('G',[2 2]);
H = sym('H' ,[1 2]);
sol = solve([A B;C 0]*[G;H] == [G*Am;Cm], [G(:); H(:)]);
Gsol = subs(G, sol)
Hsol = subs(H, sol)

10 Comments

Thanks for the help , but when i run the code it's showing sol=[empty sym],Gsol=[empty sym],Hsol=[empty sym]
Which release are you using? I tested in R2017a and R2018a... Oh wait, I see you marked R2013a. I will test more.
A=[0 1;1 -2]; B=[0;1]; C=[1 0]; Am=[0 1;-1 0]; Cm=[1 0.5];
G = sym('G',[2 2]);
H = sym('H' ,[1 2]);
sol = solve([A B;C 0]*[G;H] == [G*Am;Cm]);
Gsol = subs(G, sol)
Hsol = subs(H, sol)
Tested in R2013a.
yes R2013a , thanks for the effort , please let me know if it gets solved , thanks again
hey it's working now,thank you so much
sir i have another doubt , i was using the same code for another example , but it's showing
"Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in Untitled6 (line 7)
sol = solve([A B;C 0]*[G;H] == [G*Am;Cm]);"
Why is that happening ?? dimensions seems to be correct to me ..
clc
clear all
close all
A=[0 1 0;0 -0.87 42.22;0 0.99 -1.34]; B=[0 0;-17.25 -1.58;-0.17 -0.25]; C=[1 0 0]; Am=[0 0.3;-0.3 0]; Cm=[1 0];
G = sym('G',[3 2]);
H = sym('H' ,[2 2]);
sol = solve([A B;C 0]*[G;H] == [G*Am;Cm]);
Gsol = subs(G, sol)
Hsol = subs(H, sol)
Your A is 3 columns, and your B is 2 columns, so [A B] is 5 columns.
Your C is 3 columns, and 0 is 1 column, so [C 0] is 4 columns.
So you are trying to put a matrix with 4 columns at the bottom of a matrix with 5 columns.
Thanks,got it , but still not getting the whole matrix , here is the code
clc
clear all
close all
A=[0 1 0;0 -0.87 42.22;0 0.99 -1.34]; B=[0 0;-17.25 -1.58;-0.17 -0.25]; C=[1 0 0]; Am=[0 0.3;-0.3 0]; Cm=[1 0];
G = sym('G',[3 2]);
H = sym('H' ,[2 2]);
sol = solve([A B;C [0 0]]*[G;H] == [G*Am ;Cm]);
Gsol = subs(G, sol)
Hsol = subs(H, sol)
The output is :
A and B are 3 rows. You put C on the bottom of [A B] and C has 1 row, so [A B; C 0 0] is 4 rows total, each of which has 5 columns. [G; H] is 5 rows by 2 columns. (4 x 5) * (5 x 2) gives a 4 x 2 array. So you have 8 equations. But you have 10 variables to solve for. You do not have enough equations to solve for 10 variables simultaneously.
yes got it, thanks for the help

Sign in to comment.

More Answers (0)

Products

Release

R2013a

Community Treasure Hunt

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

Start Hunting!