Azzera filtri
Azzera filtri

How can I create an array of transfer functions without the for loop.

16 visualizzazioni (ultimi 30 giorni)
I have been trying to create an array of transfer function (tfPID) where T and K vary using vectorization, because for loop is simply too slow. I would appreciate any help in this regard. The code I have been using is given below.
thanks!
clc
clear
A=[0 0 0 1 0 0 0 0 0;0 0 0 0 1 0 0 0 0;0 0 0 0 0 1 0 0 0;-0.003184 0 0 0 0 -0.0199 0 0 0.0199;0 0.0002985 0 0 0 0 0 0 0;0 0 -0.000398 0.00997 0 0 -0.00997 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 0 0];
B=[0 0 0;0 0 0;0 0 0;-1 0 0;0 -0.25 0;0 0 -0.5;1 0 0;0 1 0;0 0 1];
C=[1 0 0 0 0 0 0 0 0;0 1 0 0 0 0 0 0 0;0 0 1 0 0 0 0 0 0];
D=0;
sys = ss(A,B,C,D);
i=tf(sys);
xaxis=i(1,1);
yaxis=i(1,2);
zaxis=i(1,3);
K=-5001:5:5004;
T=-5001:5:5004;
p=1:2002;
q=1:2002;
j(p)=(0.6.*(T.^2).*K);
k(p)=4.8.*K.*T;
l(p)=9.6.*K;
num=[j;k;l];
q(p)=8.*T;
w(p)=0;
den=[q;w];
tfPID(p,q)=tf(num(:,p),den(:,q));
  2 Commenti
Jan
Jan il 21 Feb 2018
The posted code does not contain a loop. So how can the loop be too slow?
Pulkit Sharma
Pulkit Sharma il 21 Feb 2018
The alternate code I wrote worked, but it was taking in excess of a day to solve.

Accedi per commentare.

Risposta accettata

Birdman
Birdman il 21 Feb 2018
Delete
tfPID(p,q)=tf(num(:,p),den(:,q));
and add these two lines at the end of your code:
num=num.';den=den.';
tfPID=tf(mat2cell(num(1:numel(p),:),ones(size(num,1),1)),mat2cell(den(1:numel(q),:),ones(size(den,1),1)));

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by