Azzera filtri
Azzera filtri

I my tried to use for loop to find a transfer function and root louces

2 visualizzazioni (ultimi 30 giorni)
Im trying to find the transfer function which included in the code and plot the root louces for TF3 so, i need to find them at a different value of k which is in PitchRateSen transfer function so when i run the code the transfer function and root louces plot just the for loop run for the first value of k and i dont know why
[A,B,C,D]=linmod('controlpr');
[num,den]=ss2tf(A,B,C,D);
g=tf(num,den);
for k = [2,1,3,4]
VehiicleDy_tf=tf([-0.0125,-0.054375],[1,1.456 ,0.2948 , 0.020787 ]);
ElevatorAcu_tf=tf([2],[1,2]);
PitchRateSen_tf= -k*tf('s');
Pitchgain=-5;
TF1=series(ElevatorAcu_tf,VehiicleDy_tf);
TF2=feedback(TF1,PitchRateSen_tf);
TF3=series(TF2,Pitchgain);
TF4=feedback(TF3,1);
rlocus(TF3);
end

Risposta accettata

Paul
Paul il 5 Gen 2024
I think that rlocus(TF3) clears the figure and then overwrites, so I think you're actually getting the root locus for the last value of k.
If you want four separate figures then open a new figure each time through the loop (it doesn't look like the value of k does very much)
for k = [2,1,3,4]
VehiicleDy_tf=tf([-0.0125,-0.054375],[1,1.456 ,0.2948 , 0.020787 ]);
ElevatorAcu_tf=tf([2],[1,2]);
PitchRateSen_tf= -k*tf('s');
Pitchgain=-5;
TF1=series(ElevatorAcu_tf,VehiicleDy_tf);
TF2=feedback(TF1,PitchRateSen_tf);
TF3=series(TF2,Pitchgain);
TF4=feedback(TF3,1);
figure
rlocus(TF3);
end
  4 Commenti
Paul
Paul il 5 Gen 2024
You have several choices depending on your needs. One option would be to save of each instance of TF3 and its associated value of k to a container array, like a struct.
% slight change to structure of the loop
k = [2, 1, 3, 4];
for ii = 1:numel(k)
VehiicleDy_tf=tf([-0.0125,-0.054375],[1,1.456 ,0.2948 , 0.020787 ]);
ElevatorAcu_tf=tf([2],[1,2]);
PitchRateSen_tf= -k(ii)*tf('s');
Pitchgain=-5;
TF1=series(ElevatorAcu_tf,VehiicleDy_tf);
TF2=feedback(TF1,PitchRateSen_tf);
TF3=series(TF2,Pitchgain);
TF4=feedback(TF3,1);
% no need to plot the root locus for this discussion
% figure
% rlocus(TF3);
TF3a(ii).k = k(ii);
TF3a(ii).TF3 = TF3;
end
Then to see one of the TF3, for example for k = 1
TF3a(2).k
ans = 1
TF3a(2).TF3
ans = 0.125 s + 0.5437 ------------------------------------------------ s^4 + 3.456 s^3 + 3.232 s^2 + 0.7191 s + 0.04157 Continuous-time transfer function.
Or, you can stack up each instance of TF3 in an array
clear
k = [2, 1, 3, 4];
for ii = 1:numel(k)
VehiicleDy_tf=tf([-0.0125,-0.054375],[1,1.456 ,0.2948 , 0.020787 ]);
ElevatorAcu_tf=tf([2],[1,2]);
PitchRateSen_tf= -k(ii)*tf('s');
Pitchgain=-5;
TF1=series(ElevatorAcu_tf,VehiicleDy_tf);
TF2=feedback(TF1,PitchRateSen_tf);
TF3(:,:,ii) = series(TF2,Pitchgain);
TF4=feedback(TF3,1);
% no need to plot the root locus for this discussion
% figure
% rlocus(TF3);
end
Using this approach you have to remember the correspondence of each value of k to each entry in TF3. Access TF3 that corresponds to k = 1
TF3(:,:,2)
ans = 0.125 s + 0.5437 ------------------------------------------------ s^4 + 3.456 s^3 + 3.232 s^2 + 0.7191 s + 0.04157 Continuous-time transfer function.
Yet another approach is to use a tunable, or parametric, model. Here, we build the model with k as a parameter, and then sample the model for specific values of k afterwards
clear
k = realp('k',2); % default value of 2 corresponding to first element of k
% No need for a loop
VehiicleDy_tf=tf([-0.0125,-0.054375],[1,1.456 ,0.2948 , 0.020787 ]);
ElevatorAcu_tf=tf([2],[1,2]);
PitchRateSen_tf= -k*tf('s');
Pitchgain=-5;
TF1=series(ElevatorAcu_tf,VehiicleDy_tf);
TF2=feedback(TF1,PitchRateSen_tf);
TF3=series(TF2,Pitchgain);
TF4=feedback(TF3,1);
Now, get TF3 for the value of k = 1
tf(sampleBlock(TF3,'k',1)) % tunable models are ss, so convert to tf if that is what is really desired
ans = 0.125 s + 0.5438 ------------------------------------------------ s^4 + 3.456 s^3 + 3.232 s^2 + 0.7191 s + 0.04157 Continuous-time transfer function.
The display of the last coefficient in the numerator in rounded to 0.5438, but if you check the actual value it's the same as in the previous case down to the last digit. There will, of course, be very slight diiferences between this method and the previous ones because the underlying numerical computations are different.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by