solving symbolic inverse of big matrix takes long
조회 수: 19 (최근 30일)
이전 댓글 표시
I would like to solve a symbolic linear system looking like this: (A1*s+A2)*x=(B1*s+B2)*u
where: x...states, u.... input, A1,A2,B1,B2.... numeric matrizes, s...laplace variable
I tried multiple approaches such as:
linsolve(A1*s+A2,B1*s+B2)
(A1*s+A2)\(B1*s+B2)
inv(A1*s*A2)*(B1*s+B2)
Minimalexample:
s=sym('s');
A1=rand(15);
A2=rand(15);
B1=ones(15,1);
B2=ones(15,1);
tic; (A1*s+A2)\(B1*s+B2); toc
Elapsed time is 35.918775 seconds.
The most expensive computation is taken by the inverse of (A1*s+A2).
Is there a way to further reduce the computation time? Goal is to calculate only one component of x. I actually don't need the solution for all x but since the system is coupled I don't see a way to further decrease the complexity.
댓글 수: 0
답변 (1개)
Aditya Patil
2021년 5월 21일
In this case, using inverse is much faster than mldivide.
N = 15;
syms s
A1=rand(N);
A2=rand(N);
B1=rand(N,1);
B2=rand(N,1);
x = (A1*s+A2);
y = (B1*s+B2);
tic; result1 = x\y; toc;
tic; result2 = inv(x) * y; toc;
sum(abs(subs(result1, s, 1) - subs(result2, s, 1)))
I tried the code for various sizes of N, and inverse is faster for this problem.
Regarding avoiding inverse, MATLAB doesn't provide any inbuilt functionality for this. However, you can implement custom code which calculates only the required components of the inverse, and uses them in the equation. This might not give major performance gain though.
댓글 수: 0
참고 항목
카테고리
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!