solving symbolic inverse of big matrix takes long
7 views (last 30 days)
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:
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.
Aditya Patil on 21 May 2021
In this case, using inverse is much faster than mldivide.
N = 15;
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.