1
\$\begingroup\$

I have a closed loop system which I am testing in MALTAB and Simulink, expecting the same output.

MATLAB

num_plant = [0.0001 10];
den_plant = [0.005 5 0.6616 61.01 2.11 20];
G1 = tf(num_plant, den_plant)

num_controller = [46615 6526 5.722e05 2.389e04 2.001e05]
den_controller = [1 404 41605 162000 200000]

C2 = tf(num_controller, den_controller)
G2=G1*C2; %G1 is same 5th order TF as Simulink
new2 = feedback(G2, 1);
step(new2)

Note:

G1 =

                       0.0001 s + 10
  --------------------------------------------------------
  0.005 s^5 + 5 s^4 + 0.6616 s^3 + 61.01 s^2 + 2.11 s + 20

C2 =

  46615 s^4 + 6526 s^3 + 572200 s^2 + 23890 s + 200100
  ----------------------------------------------------
     s^4 + 404 s^3 + 41605 s^2 + 162000 s + 200000

enter image description here

SIMULINK

enter image description here


According to the official documentation, feedback should be doing what I am presenting with blocks in Simulink. Surely I am missing something. I checked the code and everything should be the same in both cases. What is the reason for this discrepancy?

AS per JonRB's answer:

>> which step -all
C:\Program Files\MATLAB\R2018a\toolbox\control\ctrlobsolete\step.m
C:\Program Files\MATLAB\R2018a\toolbox\shared\controllib\engine\@DynamicSystem\step.m  % DynamicSystem method
C:\Program Files\MATLAB\R2018a\toolbox\ident\ident\@iddata\step.m                      % iddata method
C:\Program Files\MATLAB\R2018a\toolbox\matlab\system\@system\step.m                    % system method

Anything suspicious?

\$\endgroup\$
  • \$\begingroup\$ Well it looks like you just edited your question a few times to what I thought was wrong so I'm glad you were reading my mind. Anyways... Your time scale is radically different than your MATLAB plot and your Simulink plot? What if they were the same scale? I see a tiny plateau on your Simulink plot that looks like your MATLAB plot. \$\endgroup\$ – KingDuken Jan 7 at 21:57
  • \$\begingroup\$ I can't believe I missed that! Thanks for you contribution, you are right. I updated the question... Still, however, the graphs don't look identical to me. Could there be something else which I'm missing? \$\endgroup\$ – Rrz0 Jan 7 at 22:03
2
\$\begingroup\$

I would say you are doing something wrong in using matlab

num_plant = [0.0001 10];
den_plant = [0.005 5 0.6616 61.01 2.11 20];
G1 = tf(num_plant, den_plant)

num_controller = [46615 6526 5.722e05 2.389e04 2.001e05]
den_controller = [1 404 41605 162000 200000]

C2 = tf(num_controller, den_controller)
G2=G1*C2; %G1 is same 5th order TF as Simulink
new2 = feedback(G2, 1);
step(new2,50)
grid

This produces: enter image description here

And in simulink

enter image description here

All intent and purposes... identical.

enter image description here

In fact executing: [y,t] = step(new2,50) and playing back in Simulink shows this

\$\endgroup\$
  • \$\begingroup\$ Thanks for taking the time to try this out. Strange, I keep getting the original response in the question. Could it be that I'm using a different solver or something of the sort? \$\endgroup\$ – Rrz0 Jan 7 at 22:55
  • \$\begingroup\$ Maybe JonRB is using a later version. \$\endgroup\$ – Harry Svensson Jan 7 at 23:05
  • \$\begingroup\$ I am using R2018b but the step command hasn't changed in over a decade. Looking at the stype of @Rrz0 simscape scopes, he is using at least R2016a. At this point I would delete the local user profile MATLAB settings directory to see if some single-precision option in matlab was enabled \$\endgroup\$ – JonRB Jan 7 at 23:11
  • \$\begingroup\$ I am on R2018a. WiIl look into this further. Thanks \$\endgroup\$ – Rrz0 Jan 7 at 23:19
  • 1
    \$\begingroup\$ Performed all the steps given mathworks.com/matlabcentral/answers/… but I still get the same response. \$\endgroup\$ – Rrz0 Jan 7 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.