How can I solve A*X + X*B = C equation for X? where A, B&C are 2*2 matrixes.
조회 수: 2 (최근 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에서 Systems of Nonlinear Equations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!