# Confusion calculating steady state error in MATLAB?

I am trying to use MATLAB to calculate steady state error I have found a weblink that gives code for finding steady state error but when i use that code i get value of steady error to be greater than 1, while in my understanding steady state error should be less than 1,because formula of steady state error in case of step input= 1/(1+k)

and the code suggested there is

sserror=abs(SP-y(end))

When i try to incorporate above code into my code to get steady state error

my code is below:

clc;clear all;close all
%defining parameters values
Ra=1
Kt=10
Kb=0.1
j=2
b=0.5
%defining numerator & denominator of system1 (1/js+b)
num=[1]
den=[j b]
% creating transfer function for system 1
sys1=tf(num,den)
%Applying block diagram reduction and simplification techniques
sys2=(-Kb)*Kt/Ra
%Creating a positive feedback system from above two systems sys1 and sys2
a=feedback(sys1,sys2,1)
%Introducing the effect of disturbance input
OL=-1*a
%Calculating step response & extracting amplitude & time matrices
[y,t]=step(OL)
%Plotting  values of amplitude matrix extracted from  step resposne
plot(y)
%Calculating length(total number of elements) for timing matrix
z=length(t)
%Finding value of last element of amplitude matrix
%That is also value of steady state speed
SP=1 % set point incase of step input
sserror=abs(SP-y(end))


Actually I am trying to simulate a block diagram from book , Modern Control system

and i am also attaching snapshot of that block diagram

Basically there are two block diagrams in snapshot ,one is for open loop control system and other is for close loop control system

I am considering and trying to write code for open loop system

Update: Note: Plot has been added in response to comment

• Can you post a time versus value plot of the signal?
– AJN
Sep 30 at 15:45
• If the set point is positive, then clearly the steady state error is more than one since the response is negative value.
– AJN
Oct 1 at 8:30
• Good day. I don't have an answer to the question but wanted to ask the name/title of the book where are figures 4.7 and 4.9 from. Could you say, please? Nov 21 at 10:17
• @Agasha - Hi, I didn't write the question, but I believe I recognise the figures as being from the book "Modern Control Systems" by Richard C. Dorf and Robert H. Bishop. Hopefully LECS can confirm that. Nov 21 at 15:47

I think you should be treating at the system like this, and analyze the system this way, taking $$\T_d(s)\$$ as your main input. With such a diagram, the definition for sys2 and sys1 changes, as you might notice. It becomes the formula below.

$$sys2=\frac{K_m(K_tK_b+K_a)}{R_a}$$ $$sys1=\frac{-1}{Js+b}$$

Rewriting the code according to this might yield a correct result.

a=feedback(sys1,sys2,1)

OL=-1*a

[y,t]=step(OL)


The output of the closed loop system is negated before it is supplied to the step function.

So even though the output of the original system a is going to 0.66 (steady state error 0.33), due to the negation of the output in OL, the calculation returns 1.66 > 1.

What is the reason / logic for doing OL = -1 * a ?

## Note

There is one logical error also.

[y,t]=step(OL)         % SP is NOT the input given here!
SP=1                   % the set point has NO effect on y !
sserror=abs(SP-y(end)) % this calculation is hence invalid


Since the step function is called before setting the setpoint SP, the calculation SP - y(end) is invalid since SP was not the input actually supplied to the system.

The code in the link you provided in the question has the correct order of operations.

SP=5; %input value, if you put 1 then is the same as step(sys)
[y,t]=step(SP*sys); %get the response of the system to a step with amplitude SP
sserror=abs(SP-y(end)) %get the steady state error