In: Electrical Engineering
Need to use math lab for the Isim function for calculating the output and state response.
Of the Transfer Function s + 2 / s^2 + 2 s + 2. I been using the following code and it doesn’t work
sys = tf([1 2],[1 2 2])
t = [0:0.01:];
u=0*t;
[y,T,x] = lsim(sys,u,t)
subplot(121), plot(T,x(:,1))
xlabel('Time(s)'),ylabel('x_1')
subplot(122),plot(T,x(:,2))
xlabel('Time(s)'),ylabel('x_2')
lsim fuction is used for time respose of any input it has different format for different system representation for example
[y,T] = lsim(s,u,t) this format used for transfer functions
[y,T,x] = lsim(s,u,t,x0) this format used for state spae-type system respose
so for state-space response system will be in state form for this use "ss" command to convet from transfer function to state-space model of any given system
the missing part of your code is as follow
1) time 't' expression should be complete
2) input 'u' should be spacified not zero other wise response should be zero for zero initial state x0
3) sys should be in state-space form
all other part of code is correct
the matlab code and result is given as follow
%system transfer function
sys=tf([1,2],[1,2,2]);
%time vector
t=[0:0.01:5];%0 to 5 sec with 0.01 sec step
%input vector
u1=ones(1,length(t));%for unit step input
u2=[1,zeros(1,(length(t)-1))] %for impulse input
%for state responce system system should be in state-space form
transfer function to state-space conversion
sys= ss(sys);
[y,T,x] = lsim(sys,u1,t);%for step response
subplot(221), plot(T,x(:,1));%for first state x1 plot
xlabel('Time(s)');ylabel('x_1');
subplot(222);plot(T,x(:,2));%for second state x2 plot
xlabel('Time(s)');ylabel('x_2');
subplot(223), plot(T,y);%for output y plot
xlabel('Time(s)');ylabel('y');
result of unit step input state response of given system
use u2 for impulse response
%system transfer function
sys=tf([1,2],[1,2,2]);
%time vector
t=[0:0.01:5];%0 to 5 sec with 0.01 sec step
%input vector
u1=ones(1,length(t));%for unit step input
u2=[1,zeros(1,(length(t)-1))]; %for impulse input
%for state responce system system should be in state-space form
transfer function to state-space conversion
sys= ss(sys);
[y,T,x] = lsim(sys,u2,t);%for impulse response
subplot(221), plot(T,x(:,1));%for first state x1 plot
xlabel('Time(s)');ylabel('x_1');
subplot(222);plot(T,x(:,2));%for second state x2 plot
xlabel('Time(s)');ylabel('x_2');
subplot(223), plot(T,y);%for output y plot
xlabel('Time(s)');ylabel('y');
result of unit impulse state response of given system