How to tell solver that symbols are matrices
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
更多回答(1 个)
John D'Errico
2021-5-2
编辑:John D'Errico
2021-5-2
A = sym('a',[2,2])
As you can see, A is a 2x2 matrix.
B = rand(2,2);
X = rand(2,2);
Asol = solve(A*X == B,A)
So now, for example, we see a1_1 is
Asol.a1_1
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!