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

1 次查看(过去 30 天)
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.

采纳的回答

sruthi gundeti
sruthi gundeti 2020-9-13
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 个评论
arturo pietri
arturo pietri 2020-9-14
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 2020-9-15
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?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 General Applications 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by