How can I tune a block parameter till I retrieve a desired output?

1 vue (au cours des 30 derniers jours)
arturo pietri
arturo pietri le 11 Sep 2020
Commenté : arturo pietri le 15 Sep 2020
I would like to be able to run a simulation which tunes the gain value 'A' (The amplitude of my sine wave) so that for a given maximum amplitude of {\theta}, the simulation runs till it finds an appopriate gain 'A' value.
For example: If I would like my {\theta} amplitude to be no more than 2, then for all other values which my {\theta} maximum amplitude does not reach or surpass 2, tune 'A' for values which my {\theta} would achieve a maximum amplitude of 2.
I have tried:
a) Work with If / Else. But this does not allow subsystems with multiple actions.
b) Try using the Logic function 'Compare'. But did not find a proper way to tune 'A'
c) I tried adding a PID, rather than using 'A' as a gain, I would use P as my 'A' value. But did not try further with the I nor D controller for tuning the signal.
d) I tried reworking the whole system. Rather than start integrating from \ddot{\theta}, I started to differentiate from {\theta} (as then I would define my {\theta} as an input rather than a fixed ouput). Never tried this one before, therefore my system would give strange results.

Réponse acceptée

sruthi gundeti
sruthi gundeti le 13 Sep 2020
Define Gain 'A' Value From Workspace and Output Variable as To workspace variable and use Data Inspector to record each simulation output
By using m- script
In a for loop
1. change the value Gain A
2. Run the simulation
3.When the Output variable satisfies the criteria ,Break the loop
4.Going over large number of simulations can collapse matlab so limit the iterations of Gain A values and check the results manually to decide the appopriate gain 'A' value.
  2 commentaires
arturo pietri
arturo pietri le 14 Sep 2020
Thank you for your reply.
I gotta check on my side now. I got a little bit stuck with the m- script and the For loop. Because when I used the From Workspace block in simulink, it would run in a double variable (time series).
So I am here still learning how to write the m- script, the for loop.
arturo pietri
arturo pietri le 15 Sep 2020
Hello!
I tried following your suggestion. This is what I did:
1) Defined my Gain A value as a variable From Workspace block.
2) Defined my output (phi) as a variable To Workspace block.
3) Created a for loop m-script which looks as the follow:
for i = 0.001:0.0025:0.1
A = [0 i];
%Load model
load_system('Model1');
%Simulate Model
sim('Model1');
% Open the Simulation Data Inspector
Simulink.sdi.view;
% retrieve phi values from output Simulation
phi = ans.get('phi')
if phi == 2
break
end
end
Thank you again for your suggestion!!
Only detail that I am missing is the break condition (to stop simulation when phi == 2). Which is not working.
I am not sure if I am retrieving correctly the To Workspace variable (phi) by: phi = ans.get('phi') , or if my If statement is quite vague. Do I create a new post and accept your answer?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur General Applications dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by