How to tell solver that symbols are matrices

조회 수: 2 (최근 30일)
Ahmet Parker
Ahmet Parker 2021년 5월 2일
댓글: Ahmet Parker 2021년 5월 2일
Hi,
I want to solve an equation which involves matrices. I could not tell matlab the variables are matrices. I need something like
a=matrix(a,[n1,n2]);
b=matrix(b,[n3,n4]);
where n1 n2 n3 n4 are dimensions of matrices then I want to solve
solve(a+b*a^2==2b,a) (This equation is not the real equation, my equation is very long and I have more than a and b variables (lots of variables)
a and b are symbolic meaning
syms a b
Thanks

채택된 답변

Steven Lord
Steven Lord 2021년 5월 2일
편집: Steven Lord 2021년 5월 2일
If you're using release R2021a or later and have Symbolic Math Toolbox, create a symbolic matrix variable using the syms or symmatrix functions. See the Release Notes for more information.
syms A [3 3] matrix
syms B [3 3] matrix
y = A*B-B*A % not necessarily 0
y = 
  댓글 수: 1
Ahmet Parker
Ahmet Parker 2021년 5월 2일
Thank you very much. I have a tah license for R2021a

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

John D'Errico
John D'Errico 2021년 5월 2일
편집: John D'Errico 2021년 5월 2일
A = sym('a',[2,2])
A = 
As you can see, A is a 2x2 matrix.
B = rand(2,2);
X = rand(2,2);
Asol = solve(A*X == B,A)
Asol = struct with fields:
a1_1: [1×1 sym] a2_1: [1×1 sym] a1_2: [1×1 sym] a2_2: [1×1 sym]
So now, for example, we see a1_1 is
Asol.a1_1
ans = 
  댓글 수: 2
Ahmet Parker
Ahmet Parker 2021년 5월 2일
Sir thank you for the answer. I know this method. However I am trying to get results in terms of a and b since I am trying to find a formula in terms of a and b, not a1_1 and b1_2 in example.
Ahmet Parker
Ahmet Parker 2021년 5월 2일
my equation and solution must obey matrix algebra rules

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by