function zpk and linmod

How are matrices A,B,C,D found?
How is the calculation done to find the transfer function gains?
Example:
X_trim =
0.0156566822191464
0.0795424262493709
196.412468864823
15.6561280499959
0
-3048
U_trim =
-0.091567106993385
[A,B,C,D]=linmod(modelName,X_trim,U_trim)
A =
x1 x2
x1 -0.7302 195.5
x2 -0.1373 -0.67
B =
u1
x1 -25.91
x2 -36.5
C =
x1 x2
y1 -0.7302 195.5
y2 0 1
D =
u1
y1 -25.91
y2 0
-25.905 s (s+276.1)
az: --------------------
(s^2 + 1.4s + 27.32)
-36.503 (s+0.6328)
q: --------------------
(s^2 + 1.4s + 27.32)

Answers (2)

Once you have the state-space, you can apply the zpk() function to obtain the TF in zpk mode.
A = [-0.7302 195.5
-0.1373 -0.67];
B = [-25.91
-36.5];
C = [-0.7302 195.5
0 1];
D = [-25.91
0];
sys = ss(A, B, C, D)
sys = A = x1 x2 x1 -0.7302 195.5 x2 -0.1373 -0.67 B = u1 x1 -25.91 x2 -36.5 C = x1 x2 y1 -0.7302 195.5 y2 0 1 D = u1 y1 -25.91 y2 0 Continuous-time state-space model.
G = zpk(sys)
G = From input to output... -25.91 s (s+276.1) 1: -------------------- (s^2 + 1.4s + 27.33) -36.5 (s+0.6327) 2: -------------------- (s^2 + 1.4s + 27.33) Continuous-time zero/pole/gain model.

3 Comments

My reading of the question is that it is asking what the mathematics of finding the matrices is.
Yes, how find A,B,C,D?
Sam Chak
Sam Chak on 10 Oct 2024
Edited: Sam Chak on 10 Oct 2024
I don't know the algorithm used in the linmod.m file. However, the state-space matrices A, B, C, D are obtained by computing the Jacobian with respect to the trim condition.

Sign in to comment.

Aquatris
Aquatris on 11 Oct 2024
Here explains how it is done. Basically you have your function that describes the relation between states and inputs. If they are nonlinear functions, you use Jacobian to linearize the relation at a particular operating point, depicted with x_trim and u_trim in your example.
Once you have a state space representation, then you can convert it to a transfer function. From the transfer function, finding the zeros poles and gain are a simple mathematical manipulation to make the transfer function look like this

8 Comments

How do I find the values ​​of matrices A,B,C,D?
The link explains it but I guess you do not know how to translate it to your problem. Share what you have in your "modelname", which I believe is a simulink file, and we might be able to provide you your answer.
%% Find Names and Ordering of States
[sizes,x0,names]=airframe3DoF([],[],[],'sizes');
% sizes
% x0 [valores para cada names]
% names [q,theta,U,w,x,y] posicoes: q=1,theta=2, U=3, w=4, x=5, y=6.
state_names = cell(1,numel(names));
for i = 1:numel(names)
n = max(strfind(names{i},'/')); %numero maximo de caracteres sem contar as barras.
state_names{i}=names{i}(n+1:end);
end
%% Specify States
% Specify which states to trim and which states remain fixed.
fixed_states = [{'U,w'} {'Theta'} {'Position'}]; % ix estados que nao mudam (nao trimam)
fixed_derivatives = [{'U,w'} {'q'}]; % idx % wponto = az; q = thetaponto; qponto = thetapontoponto estados que quero trimar
fixed_outputs = [];
% fixed_outputs = vazio
fixed_inputs = [];
% fixed_inputs = vazio
n_states=[];n_deriv=[];
for i = 1:length(fixed_states)
%length(fixed_states): tamamnho do fixed_states = 1 x 3
n_states=[n_states find(strcmp(fixed_states{i},state_names))]; %#ok<AGROW>
% n_states = 1 x 5; posicoes do fixed_states em relacao aos names]: [3 4 2 5 6] = [U w theta x y]
end
for i = 1:length(fixed_derivatives)
n_deriv=[n_deriv find(strcmp(fixed_derivatives{i},state_names))]; %#ok<AGROW>
% n_derivatives = 1 x 3; posicoes do fixed_derivatives em relacao aos names: [3 4 1] = [U w q]
end
n_deriv=n_deriv(2:end);
% pegando os valores da segunda posicao ate a ultima, nao pega a primeira posicao, porque??? [4 1] = [w q]
%%% estava alterando o valor quando mudava o fixed_derivatives por conta da
%%% linha 71 pois ele pega do segundo valor em diante e nao pega o
%%% primeiro.
%% Trim Model
% Trim the model.
[X_trim,U_trim,Y_trim,DX,options]=trim(modelName,x0,0,[0 0 simSetup.initCond.velocityIC]', ...
n_states,fixed_inputs,fixed_outputs, ...
[],n_deriv)
options(10) % retorna o numero de iteracoes usadas para encontrar um ponto de corte.
%[x,u,y,dx] = trim('sys',x0,u0,y0,ix,iu,iy,dx0,idx)
% x0 = [valores iniciais para cada names]
% u0 = 0
% y0 = [0; 0; velocidadeIC]
% ix = n_states = 1 x 5; posicoes do fixed_states em relacao aos names]: [3 4 2 5 6] = [U w theta x y]
% iu = fixed_inputs = vazio
% iy = fixed_outputs = vazio
% dx0 = vazio %valores da derivada de estado no ponto inicial da busca
% idx = n_deriv pegando os valores da segunda posicao ate a ultima, nao pega a primeira posicao, porque??? [4 1] = [w q]
% idx seleciona os valores dx0 que a busca deve satisfazer exatamente.
%% Linear Model and Frequency Response
% Derive the linear model and view the frequency response.
fmt = format("longG");
% opts(3);
[A,B,C,D]=linmod(modelName,X_trim,U_trim),fmt;
% [A,B,C,D]=linmod(modelName,X_trim,U_trim),opts;
A
if exist('control','dir')
airframe = ss(A(n_deriv,n_deriv),B(n_deriv,:),C([2 1],n_deriv),D([2 1],:));
set(airframe,'StateName',state_names(n_deriv), ...
'InputName',{'Elevator'}, ...
'OutputName',[{'az'} {'q'}]);
zpk(airframe)
linearSystemAnalyzer('bode',airframe)
end
What is airframe3DoF, modelname, options?
model made by me in simulink
Yes I understand they are a model or script. However how do you expect us to answer your question if you do not give us a clear question without any unknowns like what is in those models. The models might be simple transfer function blocks, might be user defined matlab functions, might be a simple gain block. Although it does not change the mathematics behind how you obtain the state space matrices for those blocks, the result is different. What exactly is it that you want as an answer to your question here?
Would you like to understand how the matrices A,B,C,D are calculated?
Loading these files generates two transfer functions, one az and the other q. I would like to know how the calculation of matrices A, B, C and D is done?

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!