Inverting an 8x8 symbolic matrix

14 views (last 30 days)
Luis
Luis on 27 Apr 2025
Commented: Paul on 27 Apr 2025
I am trying to invert an 8x8 symbolic matrix with 32 symbolic variables in total. However, when running the standard inversion methods with inv() or mldivide(), the program takes a lot of time and ended up crashing all the times I tried to invert this matrix. I tried some workarounds, such as a recursive inversion algorithm using Schur decomposition and other ways of using the fact that I know that the matrix is symmetric, but to no avail. The function has a lot of sines and cosines of these variables, which might also be a problem.
I am looking for ways I can get this matrix inverted, or any further suggestion on how to tackle this problem.
Thanks in advance.
For context: the matrix I am trying to invert is the inertia matrix for a tiltrotor UAV. the 32 parameters consist of 6 state variables and 26 model parameters. My goal with this is to get an analytic expression for the system equations of motion:
With that expression, I intend to obtain an analytic linearization of the system in order to get a linear model , where . With these analytical expressions should be able to easily get A, B matrices for different values of the system parameters and formulate robust linear controllers with polytopic uncertainty.
  2 Comments
Luis
Luis on 27 Apr 2025
In case anyone is curious, here is the Schur decomposition inversion I tried to implement:
function [T] = recursiveSchurInv(A)
%RECURSIVESCHURINV Summary of this function goes here
% Detailed explanation goes here
sz= size(A);
if sz(1) ~= sz(2) % matrix must be sequare
% error
end
N = sz(1);
% Edge cases: N = 1 and 2
if N == 1
T = 1/A;
elseif N == 2
T = A\eye(N);
else
% Big matrix case
% Matrix partition
A1 = A(1:2, 1:2); % 2x2
A2 = A(3:N, 3:N); % N-2 x N-2
As = A(3:N, 1:2); % N-2 x 2
As_t = As.';
% Inverse variables
A2_inv = recursiveSchurInv(A2);
D = A1 - As_t * A2_inv * As;
D_inv = recursiveSchurInv(D);
% Calculate inverse terms
T11 = D_inv;
T12 = - D_inv * As_t* A2_inv;
T21 = T12.';
T22 = A2_inv * ( eye(N-2) + As * D_inv * As_t * A2_inv );
T = [T11, T12;
T21, T22];
end
end
Note that it assumes that the matrix is symmetric (again, I was trying to capitalize on that).
Paul
Paul on 27 Apr 2025
Hi Luis,
Can you upload or show the form of the M(q) matrix? By form, I mean just show the 8x8 matrix generically indicating which terms are zero and which are not (we already know it's symmetric). In other words, what is the output of
~isAlways(M==0,'Unknown',false)

Sign in to comment.

Answers (2)

John D'Errico
John D'Errico on 27 Apr 2025
Edited: John D'Errico on 27 Apr 2025
What nobody ever seems to understand is that a symbolic inverse of a matrix like this grows exponentially in complexity. Many thousands, or millions of terms or more. (But everyone tries it, ONCE.)
Even if you could find the inverse, it would be an incredibly complicated mess. Using it would be intolerable. And then you would be complaining about how slow it is, and asking how to make it faster.
At the point where you want to use it, just substitute the values of each variable, and THEN do any computations to need to do, and do them in double precision.
Sorry. Your computer is not infinitely powerful, even though it seems that way sometimes.

Walter Roberson
Walter Roberson on 27 Apr 2025
Start with a generic symmetric matrix,
A11 A12 A13 A14 ... A18
A12 A22 A23 A24 ...
A13 A23 A33 A34 ...
inv() that. Expect it to take several tens of minutes.
Once you have the generic inverse, subs() in actual terms for the generic symbols
actual_inv = subs(invA, [A11 A12 A13...], [sin(theta)*cos(phi), cos(theta)*sin(phi), ...])
This approach will be much faster than trying to take the inv() of the original matrix.
The resulting inverse will have roughly 20000 terms in each denominator, and will be worth less than bat guano (which at least makes excellent fertilizer)
  1 Comment
John D'Errico
John D'Errico on 27 Apr 2025
A sagacious comment about the expected value of the result! Quite accurate.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!