solving symbolic inverse of big matrix takes long
9 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Aditya Patil
on 21 May 2021
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 Comments
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!