# How to estimate how long the inversion process will take?

2 views (last 30 days)
Ali Almakhmari on 1 Aug 2023
Answered: Steven Lord on 1 Aug 2023
Okay, so below you can find my code. What I am trying to do is basically solve for H(s), which are the transfer functions for this very very complicated dynamic system I have. The thing is, I have been running this code for 3 solid days on a machine with 128 cores and 512 GB RAM, and the code is still not done.
So my question is...how long is it supposed to take? I am sure its the inverse part in H(s) that is taking this long. My ultimate goal is to determine whether this process is feasible in less than a month or not. If not, then I might want to stop it.
clear
clc
%Defining the Symbolic Variables
syms ksm ksn ksl wsm wsn wsl Delsm Delsn Delsl DelT m Delgx Delgy Delgz dx
syms tilda_Xu ro tilda_Xv qo tilda_Xw tilda_Xp wo tilda_Xq vo tilda_Xr tilda_Yu tilda_Yv po tilda_Yw uo tilda_Yp tilda_Yq tilda_Yr tilda_Zu tilda_Zv tilda_Zw tilda_Zp tilda_Zq tilda_Zr tilda_Lu tilda_Lv tilda_Lw tilda_Lp tilda_Ixx tilda_Lq tilda_Lr tilda_Mu tilda_Mv tilda_Mw tilda_Iyy tilda_Mp tilda_Mq tilda_Mr tilda_Nu tilda_Nv tilda_Nw tilda_Np tilda_Nq tilda_Nr tilda_Izz
syms tilda_X_delm tilda_X_deln tilda_X_dell tilda_Y_delm tilda_Y_deln tilda_Y_dell tilda_Z_delm tilda_Z_deln tilda_Z_dell tilda_L_delm tilda_L_deln tilda_L_dell tilda_M_delm tilda_M_deln tilda_M_dell tilda_N_delm tilda_N_deln tilda_N_dell mu_sm mu_sn mu_sl
%% DEFINITION
% Defining B Matrix
X = [0,0,0;0,0,0;0,0,0;0,0,0;0,0,0;0,0,0;0,0,0;0,0,0;0,0,0;ksm*wsm^2,0,0;0,ksn*wsn^2,0;0,0,ksl*wsl^2];
Z = [(DelT./m + Delgx);Delgy;Delgz;0;0;0;0;0;0;0;0;0];
U = [Delsm;Delsn;Delsl];
B = X*U + Z; %The B matrix
% Defining A Matrix
F =[tilda_Xu, (ro+tilda_Xv) (-qo+tilda_Xw) tilda_Xp (-wo+tilda_Xq) (vo+tilda_Xr); (-ro+tilda_Yu) tilda_Yv (po+tilda_Yw) (wo+tilda_Yp) tilda_Yq (-uo+tilda_Yr); (qo+tilda_Zu) (-po+tilda_Zv) tilda_Zw (-vo+tilda_Zp) (uo+tilda_Zq) tilda_Zr; tilda_Lu tilda_Lv tilda_Lw tilda_Lp (tilda_Ixx*ro + tilda_Lq) (tilda_Ixx*qo + tilda_Lr); tilda_Mu tilda_Mv tilda_Mw (tilda_Iyy*ro + tilda_Mp) tilda_Mq (tilda_Iyy*po + tilda_Mr); tilda_Nu tilda_Nv tilda_Nw (tilda_Izz*qo + tilda_Np) (tilda_Izz*po + tilda_Nq) tilda_Nr];
G = [tilda_X_delm tilda_X_deln tilda_X_dell; tilda_Y_delm tilda_Y_deln tilda_Y_dell; tilda_Z_delm tilda_Z_deln tilda_Z_dell; tilda_L_delm tilda_L_deln tilda_L_dell; tilda_M_delm tilda_M_deln tilda_M_dell; tilda_N_delm tilda_N_deln tilda_N_dell];
A = [F, G, zeros(6,3);zeros(3,6),zeros(3,3),eye(3);zeros(3,6), [-wsm^2,0,0;0,-wsn^2,0;0,0,-wsl^2], [-2*mu_sm*wsm,0,0;0,-2*mu_sn*wsn,0;0,0,-2*mu_sl*wsl]]; %The A matrix
% Defining C Matrix
HH = [0,0,0,1,0,0;0,0,0,0,1,0;0,0,0,0,0,1;tilda_Xu,tilda_Xv,tilda_Xw,tilda_Xp,(tilda_Xq-2*qo*dx) (tilda_Xr-2*ro*dx); (tilda_Yu+tilda_Nu*dx) (tilda_Yv+tilda_Nv*dx) (tilda_Yw+tilda_Nw*dx) (tilda_Yp+(qo+tilda_Izz*qo+tilda_Np)*dx) (tilda_Yq+(po+tilda_Izz*po+tilda_Nq)*dx) (tilda_Yr+tilda_Nr*dx); (tilda_Zu-tilda_Mu*dx) (tilda_Zv-tilda_Mv*dx) (tilda_Zw-tilda_Mw*dx) (tilda_Zp+(ro-tilda_Iyy*ro-tilda_Mp)*dx) (tilda_Zq-tilda_Mq*dx) (tilda_Zr+(po-tilda_Iyy*po+tilda_Mr)*dx)];
J = [0 0 0; 0 0 0; 0 0 0; tilda_X_delm tilda_X_deln tilda_X_dell; (tilda_Y_delm+tilda_N_delm*dx) (tilda_Y_deln+tilda_N_deln*dx) (tilda_Y_dell+tilda_N_dell*dx); (tilda_Z_delm-tilda_M_delm*dx) (tilda_Z_deln-tilda_M_deln*dx) (tilda_Z_dell-tilda_M_dell*dx)];
C = [HH J zeros(6,3)]; %The C matrix
% Defining D Matrix
D = [0;0;0;(DelT./m + Delgx);Delgy;Delgz]; %The D matrix
%% EDIT
B = [X ones(12,12) zeros(12,6)];
D = [zeros(6,3) zeros(6,12) ones(6,6)];
%% TF
%FINDING THE TRANSFER FUNCTIONS FROM THE STATE SPACES
syms s
H(s) = C*inv(s*eye(size(A))-A)*B + D;
save("H.mat","H");

Steven Lord on 1 Aug 2023
syms ksm ksn ksl wsm wsn wsl Delsm Delsn Delsl DelT m Delgx Delgy Delgz dx
syms tilda_Xu ro tilda_Xv qo tilda_Xw tilda_Xp wo tilda_Xq vo tilda_Xr tilda_Yu tilda_Yv po tilda_Yw uo tilda_Yp tilda_Yq tilda_Yr tilda_Zu tilda_Zv tilda_Zw tilda_Zp tilda_Zq tilda_Zr tilda_Lu tilda_Lv tilda_Lw tilda_Lp tilda_Ixx tilda_Lq tilda_Lr tilda_Mu tilda_Mv tilda_Mw tilda_Iyy tilda_Mp tilda_Mq tilda_Mr tilda_Nu tilda_Nv tilda_Nw tilda_Np tilda_Nq tilda_Nr tilda_Izz
syms tilda_X_delm tilda_X_deln tilda_X_dell tilda_Y_delm tilda_Y_deln tilda_Y_dell tilda_Z_delm tilda_Z_deln tilda_Z_dell tilda_L_delm tilda_L_deln tilda_L_dell tilda_M_delm tilda_M_deln tilda_M_dell tilda_N_delm tilda_N_deln tilda_N_dell mu_sm mu_sn mu_sl
%% DEFINITION
% Defining B Matrix
X = [0,0,0;0,0,0;0,0,0;0,0,0;0,0,0;0,0,0;0,0,0;0,0,0;0,0,0;ksm*wsm^2,0,0;0,ksn*wsn^2,0;0,0,ksl*wsl^2];
Z = [(DelT./m + Delgx);Delgy;Delgz;0;0;0;0;0;0;0;0;0];
U = [Delsm;Delsn;Delsl];
B = X*U + Z; %The B matrix
% Defining A Matrix
F =[tilda_Xu, (ro+tilda_Xv) (-qo+tilda_Xw) tilda_Xp (-wo+tilda_Xq) (vo+tilda_Xr); (-ro+tilda_Yu) tilda_Yv (po+tilda_Yw) (wo+tilda_Yp) tilda_Yq (-uo+tilda_Yr); (qo+tilda_Zu) (-po+tilda_Zv) tilda_Zw (-vo+tilda_Zp) (uo+tilda_Zq) tilda_Zr; tilda_Lu tilda_Lv tilda_Lw tilda_Lp (tilda_Ixx*ro + tilda_Lq) (tilda_Ixx*qo + tilda_Lr); tilda_Mu tilda_Mv tilda_Mw (tilda_Iyy*ro + tilda_Mp) tilda_Mq (tilda_Iyy*po + tilda_Mr); tilda_Nu tilda_Nv tilda_Nw (tilda_Izz*qo + tilda_Np) (tilda_Izz*po + tilda_Nq) tilda_Nr];
G = [tilda_X_delm tilda_X_deln tilda_X_dell; tilda_Y_delm tilda_Y_deln tilda_Y_dell; tilda_Z_delm tilda_Z_deln tilda_Z_dell; tilda_L_delm tilda_L_deln tilda_L_dell; tilda_M_delm tilda_M_deln tilda_M_dell; tilda_N_delm tilda_N_deln tilda_N_dell];
A = [F, G, zeros(6,3);zeros(3,6),zeros(3,3),eye(3);zeros(3,6), [-wsm^2,0,0;0,-wsn^2,0;0,0,-wsl^2], [-2*mu_sm*wsm,0,0;0,-2*mu_sn*wsn,0;0,0,-2*mu_sl*wsl]]; %The A matrix
% Defining C Matrix
HH = [0,0,0,1,0,0;0,0,0,0,1,0;0,0,0,0,0,1;tilda_Xu,tilda_Xv,tilda_Xw,tilda_Xp,(tilda_Xq-2*qo*dx) (tilda_Xr-2*ro*dx); (tilda_Yu+tilda_Nu*dx) (tilda_Yv+tilda_Nv*dx) (tilda_Yw+tilda_Nw*dx) (tilda_Yp+(qo+tilda_Izz*qo+tilda_Np)*dx) (tilda_Yq+(po+tilda_Izz*po+tilda_Nq)*dx) (tilda_Yr+tilda_Nr*dx); (tilda_Zu-tilda_Mu*dx) (tilda_Zv-tilda_Mv*dx) (tilda_Zw-tilda_Mw*dx) (tilda_Zp+(ro-tilda_Iyy*ro-tilda_Mp)*dx) (tilda_Zq-tilda_Mq*dx) (tilda_Zr+(po-tilda_Iyy*po+tilda_Mr)*dx)];
J = [0 0 0; 0 0 0; 0 0 0; tilda_X_delm tilda_X_deln tilda_X_dell; (tilda_Y_delm+tilda_N_delm*dx) (tilda_Y_deln+tilda_N_deln*dx) (tilda_Y_dell+tilda_N_dell*dx); (tilda_Z_delm-tilda_M_delm*dx) (tilda_Z_deln-tilda_M_deln*dx) (tilda_Z_dell-tilda_M_dell*dx)];
C = [HH J zeros(6,3)]; %The C matrix
% Defining D Matrix
D = [0;0;0;(DelT./m + Delgx);Delgy;Delgz]; %The D matrix
%% EDIT
B = [X ones(12,12) zeros(12,6)];
D = [zeros(6,3) zeros(6,12) ones(6,6)];
%% TF
%FINDING THE TRANSFER FUNCTIONS FROM THE STATE SPACES
syms s
Let's look at the size and contents of the symbolic matrix you're trying to invert.
% H(s) = C*inv(s*eye(size(A))-A)*B + D;
M = s*eye(size(A))-A;
size(M)
ans = 1×2
12 12
simplify(M)
ans =
What guarantee do you have that the inverse of this matrix even exists? [Hint: in general it doesn't. What if s and one of wsm, wsn, and wsl are 0? One of the last three rows of M would be all 0.]
I would not invert this matrix. You don't actually care about the inverse. You care about the product of the inverse and other matrices. You could try the backslash operator, but first I strongly recommend that you use subs to substitute values for as many of the symbolic variables as you can before trying to either invert or use backslash.
Yes, I suspect you'd prefer H to be a function of all seventy of your symbolic variables.
numel(symvar(M))
ans = 70
I doubt that's feasible. Even if it is possible to perform that inversion in a reasonable amount of time (measured in units less than years), the expression is almost certain to be so long that it would be unreadable and unusable.
% H = C*(M\B)+D;
You could also try telling MATLAB that all your symbolic variables are positive (to avoid the case I called out above where s and one other variable were exactly 0) but this is still going to be a terribly complicated expression in general.

Mrutyunjaya Hiremath on 1 Aug 2023
• This is the optimized the code by removing unnecessary variables and setting their initial values to zero directly in the symbolic variable declaration. Additionally, I've made some formatting adjustments for better readability.
clear
clc
% Defining the Symbolic Variables with initial values set to zero
syms ksm ksn ksl wsm wsn wsl Delsm Delsn Delsl DelT m Delgx Delgy Delgz dx
syms tilda_Xu ro tilda_Xv qo tilda_Xw tilda_Xp wo tilda_Xq vo tilda_Xr tilda_Yu tilda_Yv po tilda_Yw uo tilda_Yp tilda_Yq tilda_Yr tilda_Zu tilda_Zv tilda_Zw tilda_Zp tilda_Zq tilda_Zr tilda_Lu tilda_Lv tilda_Lw tilda_Lp tilda_Ixx tilda_Lq tilda_Lr tilda_Mu tilda_Mv tilda_Mw tilda_Iyy tilda_Mp tilda_Mq tilda_Mr tilda_Nu tilda_Nv tilda_Nw tilda_Np tilda_Nq tilda_Nr tilda_Izz
syms tilda_X_delm tilda_X_deln tilda_X_dell tilda_Y_delm tilda_Y_deln tilda_Y_dell tilda_Z_delm tilda_Z_deln tilda_Z_dell tilda_L_delm tilda_L_deln tilda_L_dell tilda_M_delm tilda_M_deln tilda_M_dell tilda_N_delm tilda_N_deln tilda_N_dell mu_sm mu_sn mu_sl
%% SETTING ZEROS (OPTIONAL)
ksm = 0; ksn = 0; ksl = 0;
wsm = 0; wsn = 0; wsl = 0;
vo = 0; wo = 0; po = 0; qo = 0; ro = 0;
tilda_Lv = 0; tilda_Lw = 0; tilda_Lq = 0; tilda_Lr = 0;
tilda_L_delm = 0; tilda_L_deln = 0;
tilda_Mu = 0; tilda_Mv = 0; tilda_Mp = 0; tilda_Mr = 0;
tilda_M_dell = 0; tilda_M_deln = 0;
tilda_Nu = 0; tilda_Nw = 0; tilda_Np = 0; tilda_Nq = 0; tilda_Nr = 0;
tilda_N_delm = 0; tilda_N_dell = 0;
tilda_Xv = 0; tilda_Xw = 0; tilda_Xq = 0; tilda_Xr = 0;
tilda_X_delm = 0; tilda_X_deln = 0;
tilda_Yu = 0; tilda_Yw = 0; tilda_Yp = 0; tilda_Yq = 0; tilda_Yr = 0;
tilda_Y_delm = 0; tilda_Y_dell = 0;
tilda_Zu = 0; tilda_Zv = 0; tilda_Zp = 0; tilda_Zr = 0;
tilda_Z_delm = 0; tilda_Z_deln = 0;
Delgx = 0; Delgy = 0; Delgz = 0; DelT = 0;
Delsm = 0; Delsn = 0; Delsl = 0; dx = 0;
uo = 0; tilda_Xp = 0; tilda_Yv = 0; tilda_Yr = 0;
tilda_Zw = 0; tilda_Zq = 0; tilda_Lu = 0; tilda_Lp = 0;
tilda_Mw = 0; tilda_Mq = 0; tilda_Nv = 0; tilda_Nr = 0;
tilda_X_dell = 0; tilda_Xu = 0; tilda_Y_deln = 0;
tilda_L_dell = 0; tilda_M_delm = 0; tilda_N_deln = 0;
mu_sm = 0; mu_sn = 0; mu_sl = 0;
%% DEFINITION
% Defining B Matrix
X = [0, 0, 0; 0, 0, 0; 0, 0, 0; 0, 0, 0; 0, 0, 0; 0, 0, 0; 0, 0, 0; 0, 0, 0; 0, 0, 0; ksm * wsm^2, 0, 0; 0, ksn * wsn^2, 0; 0, 0, ksl * wsl^2];
Z = [(DelT / m + Delgx); Delgy; Delgz; 0; 0; 0; 0; 0; 0; 0; 0; 0];
U = [Delsm; Delsn; Delsl];
B = X * U + Z; % The B matrix
% Defining A Matrix
F = [tilda_Xu, (ro + tilda_Xv), (-qo + tilda_Xw), tilda_Xp, (-wo + tilda_Xq), (vo + tilda_Xr);
(-ro + tilda_Yu), tilda_Yv, (po + tilda_Yw), (wo + tilda_Yp), tilda_Yq, (-uo + tilda_Yr);
(qo + tilda_Zu), (-po + tilda_Zv), tilda_Zw, (-vo + tilda_Zp), (uo + tilda_Zq), tilda_Zr;
tilda_Lu, tilda_Lv, tilda_Lw, tilda_Lp, (tilda_Ixx * ro + tilda_Lq), (tilda_Ixx * qo + tilda_Lr);
tilda_Mu, tilda_Mv, tilda_Mw, (tilda_Iyy * ro + tilda_Mp), tilda_Mq, (tilda_Iyy * po + tilda_Mr);
tilda_Nu, tilda_Nv, tilda_Nw, (tilda_Izz * qo + tilda_Np), (tilda_Izz * po + tilda_Nq), tilda_Nr];
G = [tilda_X_delm, tilda_X_deln, tilda_X_dell;
tilda_Y_delm, tilda_Y_deln, tilda_Y_dell;
tilda_Z_delm, tilda_Z_deln, tilda_Z_dell;
tilda_L_delm, tilda_L_deln, tilda_L_dell;
tilda_M_delm, tilda_M_deln, tilda_M_dell;
tilda_N_delm, tilda_N_deln, tilda_N_dell];
A = [F, G, zeros(6, 3); zeros(3, 6), zeros(3, 3), eye(3);
zeros(3, 6), [-wsm^2, 0, 0; 0, -wsn^2, 0; 0, 0, -wsl^2], [-2 * mu_sm * wsm, 0, 0; 0, -2 * mu_sn * wsn, 0; 0, 0, -2 * mu_sl * wsl]]; % The A matrix
% Defining C Matrix
HH = [0, 0, 0, 1, 0, 0;
0, 0, 0, 0, 1, 0;
0, 0, 0, 0, 0, 1;
tilda_Xu, tilda_Xv, tilda_Xw, tilda_Xp, (tilda_Xq - 2 * qo * dx), (tilda_Xr - 2 * ro * dx);
(tilda_Yu + tilda_Nu * dx), (tilda_Yv + tilda_Nv * dx), (tilda_Yw + tilda_Nw * dx), (tilda_Yp + (qo + tilda_Izz * qo + tilda_Np) * dx), (tilda_Yq + (po + tilda_Izz * po + tilda_Nq) * dx), (tilda_Yr + tilda_Nr * dx);
(tilda_Zu - tilda_Mu * dx), (tilda_Zv - tilda_Mv * dx), (tilda_Zw - tilda_Mw * dx), (tilda_Zp + (ro - tilda_Iyy * ro - tilda_Mp) * dx), (tilda_Zq - tilda_Mq * dx), (tilda_Zr + (po - tilda_Iyy * po + tilda_Mr) * dx)];
J = [0, 0, 0; 0, 0, 0; 0, 0, 0; tilda_X_delm, tilda_X_deln, tilda_X_dell;
(tilda_Y_delm + tilda_N_delm * dx), (tilda_Y_deln + tilda_N_deln * dx), (tilda_Y_dell + tilda_N_dell * dx);
(tilda_Z_delm - tilda_M_delm * dx), (tilda_Z_deln - tilda_M_deln * dx), (tilda_Z_dell - tilda_M_dell * dx)];
C = [HH, J, zeros(6, 3)]; % The C matrix
% Defining D Matrix
D = [0; 0; 0; (DelT / m + Delgx); Delgy; Delgz]; % The D matrix
%% EDIT
B = [X, ones(12, 12), zeros(12, 6)];
D = [zeros(6, 3), zeros(6, 12), ones(6, 6)];
%% TF
% FINDING THE TRANSFER FUNCTIONS FROM THE STATE SPACES
syms s
H(s) = C * inv(s * eye(size(A)) - A) * B + D;
save("H.mat", "H");
disp(H)
Ali Almakhmari on 1 Aug 2023
You cannot set the symbolic variables to zero. Because they are non-zero.

### Categories

Find more on Programming in Help Center and File Exchange

R2020b

### Community Treasure Hunt

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

Start Hunting!