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 ?

2 件のコメント

KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 8 月 15 日
G in both sides LHS & RHS??
siddhartha ganguly
siddhartha ganguly 2018 年 8 月 16 日
yes on both sides

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2018 年 8 月 16 日

2 投票

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 件のコメント

siddhartha ganguly
siddhartha ganguly 2018 年 8 月 17 日
編集済み: siddhartha ganguly 2018 年 8 月 17 日
Thanks for the help , but when i run the code it's showing sol=[empty sym],Gsol=[empty sym],Hsol=[empty sym]
Walter Roberson
Walter Roberson 2018 年 8 月 17 日
編集済み: Walter Roberson 2018 年 8 月 17 日
Which release are you using? I tested in R2017a and R2018a... Oh wait, I see you marked R2013a. I will test more.
Walter Roberson
Walter Roberson 2018 年 8 月 17 日
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.
siddhartha ganguly
siddhartha ganguly 2018 年 8 月 17 日
yes R2013a , thanks for the effort , please let me know if it gets solved , thanks again
siddhartha ganguly
siddhartha ganguly 2018 年 8 月 17 日
hey it's working now,thank you so much
siddhartha ganguly
siddhartha ganguly 2018 年 8 月 17 日
編集済み: Walter Roberson 2018 年 8 月 17 日
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)
Walter Roberson
Walter Roberson 2018 年 8 月 17 日
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.
siddhartha ganguly
siddhartha ganguly 2018 年 8 月 17 日
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 :
Walter Roberson
Walter Roberson 2018 年 8 月 17 日
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.
siddhartha ganguly
siddhartha ganguly 2018 年 8 月 18 日
yes got it, thanks for the help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by