Effacer les filtres
Effacer les filtres

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

16 vues (au cours des 30 derniers jours)
Pulkit Sharma
Pulkit Sharma le 21 Fév 2018
Commenté : Pulkit Sharma le 21 Fév 2018
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 commentaires
Jan
Jan le 21 Fév 2018
The posted code does not contain a loop. So how can the loop be too slow?
Pulkit Sharma
Pulkit Sharma le 21 Fév 2018
The alternate code I wrote worked, but it was taking in excess of a day to solve.

Connectez-vous pour commenter.

Réponse acceptée

Birdman
Birdman le 21 Fév 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)));
  2 commentaires
Pulkit Sharma
Pulkit Sharma le 21 Fév 2018
Thank you, this was very helpful!
Pulkit Sharma
Pulkit Sharma le 21 Fév 2018
How do I create a (p,q) array for the tfPID, I need to plot the tf response with T and K.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by