solving symbolic inverse of big matrix takes long
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Aditya Patil
el 21 de Mayo de 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 comentarios
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!