Substitute symbolic matrices into numerical matrices
3 次查看(过去 30 天)
显示 更早的评论
Let's say I am solving a linear system of Equations of the form: Ax=b at each timestep. Matrix A always always has the same structure, for instance A = [a b c; -a 2b c-d; -d 2c a]. During each timestep iteration I update the values of a, b, c ,d, but the structure of A (and of b) remains the same in terms of those symbols. Is there a way to construct a symbolic matrix and then just substitute the symbols with their updated values at each timestep rather than reconstruct the whole A matrix (and b vector) at each timestep?
Many thanks!
0 个评论
回答(1 个)
Torsten
2022-9-25
编辑:Torsten
2022-9-25
Do you know Cramer's rule ?
A = sym('A',[3 3]);
b = sym('b',[3 1]);
x = sym('x',[3 1]);
sol = solve(A*x==b,x)
And now please don't tell me that in reality, your matrix A is 50x50 :-)
2 个评论
Torsten
2022-9-25
And for such a matrix size, you use symbolic maths ? You will have much time to drink your coffee ...
Use numerical matrices and backslash without any structural analysis of the matrix:
A = rand(100);
b = rand(100,1);
x = A\b
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!