How can I solve A*X + X*B = C equation for X? where A, B&C are 2*2 matrixes.
3 ビュー (過去 30 日間)
古いコメントを表示
A = [1 1;2 3] B= [5 6;7 8] C = [11 12;13 14] Syms X; Eqn = A*X + X*B == C; solve(Eqn,X); % I'm facing difficulties to define matrix X as syms
0 件のコメント
採用された回答
その他の回答 (2 件)
Andrei Bobrov
2017 年 6 月 1 日
>> A = [1 1;2 3];
B= [5 6;7 8];
C = [11 12;13 14];
X = reshape(sym('x',[4,1],'real'),2,[]);
v = A*X + X*B - C;
v = v(:);
f = matlabFunction(v,'Vars',{X});
x = fsolve(f,[1;1;1;1])
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
x =
2.1809
-0.1489
-0.2766
1.4043
>> X = reshape(x,2,[]);
>> v = A*X + X*B - C
v =
1.0e-14 *
-0.3553 -0.3553
-0.1776 -0.5329
>>
5 件のコメント
Andrei Bobrov
2017 年 6 月 1 日
編集済み: Andrei Bobrov
2017 年 6 月 1 日
Same
>> A = [1 1;2 3] ;
B= [5 6;7 8] ;
C = [11 12;13 14] ;
syms x1 y1 x2 y2
X = [x1 y1 ; x2 y2] ;
eqn = A*X+X*B == C ;
D = solve(eqn);
X = reshape(sym('x',[4,1],'real'),2,[]);
v = A*X + X*B - C;
v = v(:);
f = matlabFunction(v,'Vars',{X});
x = fsolve(f,[1;1;1;1]);
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
>> structfun(@double,D) - x
ans =
1.0e-14 *
0.6217
-0.4469
-0.4219
0.3775
>>
Karan Gill
2017 年 6 月 5 日
You can solve this with the symbolic toolbox if you declare "X" as a matrix:
>> X = sym('x%d',[2 2])
X =
[ x11, x12]
[ x21, x22]
Then solve as usual:
>> A = [1 1;2 3];
B= [5 6;7 8];
C = [11 12;13 14];
>> eqn = A*X + X*B == C
eqn =
[ 6*x11 + 7*x12 + x21 == 11, 6*x11 + 9*x12 + x22 == 12]
[ 2*x11 + 8*x21 + 7*x22 == 13, 2*x12 + 6*x21 + 11*x22 == 14]
>> sol = solve(eqn,X)
sol =
struct with fields:
x11: [1×1 sym]
x21: [1×1 sym]
x12: [1×1 sym]
x22: [1×1 sym]
>> solX = [sol.x11 sol.x12; sol.x21 sol.x22]
solX =
[ 205/94, -13/47]
[ -7/47, 66/47]
>> vpa(solX)
ans =
[ 2.1808510638297872340425531914894, -0.27659574468085106382978723404255]
[ -0.1489361702127659574468085106383, 1.4042553191489361702127659574468]
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Equation Solving についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!