70 views (last 30 days)

sys = (2.293*s + 9.172)/(s^2 + 10.29*s + 25.17);

Kp = 5; Ki = 50; Kd = 0.5;

Jon
on 22 Sep 2020

So I see you are on the right track, you are trying to define the appropriate closed loop transfer functions but using MATLAB's feedback function instead of doing the block diagram algebra by hand. That seems like a good approach. I think you just need to look more at the details of how you are applying the feedback function.

I see you want the closed loop output of the controller to a setpoint change. In this case the forward path would be the PID controller's transfer function, but the feedback path would be the rest of the elements in the closed loop, in this case, the plant or as you call it sys. Note in your case the closed loop always consists of two elements the controller and the plant, but what part of it is the forward path and what part is the feedback path depends upon what output you are interested in. When you are interested in the plant output as the "output" then the controller and the system are in the forward path with unity feedback, that is 1 in the feedback path. When you want the controller output as the "output" then the forward path is just the controller, and the feedback path is the system.

So, for example for your y_zn calculation you should use

y_zn = lsim(feedback(zn_cont,sys),sp,t);

similar for the others.

Jon
on 26 Oct 2020 at 13:16

Hi I think you should be able to use the norm command for this. On the command line you can type doc norm to bring up the detailed documentation. In particular you will find

n = norm(v,p)

where v is the vector of values, for example the error signal you want to compute the norm of and

p = 1 gives the 1-norm, p = 2, gives the 2-Norm (Euclidean Norm), and p = inf gives the infinity norm (maximum absolute value)

Jon
on 28 Oct 2020 at 14:23

I think that these expressions will give the 1, 2, and infinity norm respectively of the argument you provide (sp - y_zn'). Be sure that both sp and y_zn' are both either row vectors or column vectors. Current versions of MATLAB allow you to subtract a column vector from a row vector, or a row vector from a column vector but this gives a matrix result, not what you want. To be sure they are both columns it is safest to subtract (sp(:) - y_zn(:)). I think from your earlier code that sp is a row and so is y_zn' so I don't think this is a problem for you, but you should check to be sure, as otherwise you will get the norm of a matrix rather than the vector which you wanted.

Otherwise I think it is a matter of how you are intrepreting the results and how you are using these norms. In some cases it may be more appropriate to normalize by the number of elements, for example the root mean square error is closely related to the 2-norm but includes a further normalization by the number of elements

Opportunities for recent engineering grads.

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

Start Hunting!
## 7 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1018258

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1018258

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1018270

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1018270

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1018636

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1018636

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1019641

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1019641

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1019695

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1019695

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1019725

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1019725

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1019743

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/597421-how-can-i-get-the-control-effort-output-of-the-pid#comment_1019743

Sign in to comment.