echo on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%  Laplace transforms of time signals x(t)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
syms t n a b c w J s             %%% "syms" defines symbolic variables  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%  "laplace" computes the Laplace transform of the given function x(t)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(laplace(t^n*exp(-a*t)))      %%%  Time function t^n*exp(a*t):
pretty(laplace(sym(1)))           %%%  Unitary step function:
pretty(laplace(t))                %%%  Unitary ramp function:
pretty(laplace(t^2/2))            %%%  Unitary parabola function:
pretty(laplace(exp(-a*t)))        %%%  Exponential function:
pretty(laplace(sin(w*t)))         %%%  Sin function:
pretty(laplace(cos(w*t)))         %%%  Cos function:
pause                           %%% Press a keybord key to continue 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%  Laplace transforms of other funcitons 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pretty(simplify(laplace(exp(-a*t)*cos(w*t)))) %%%  Exponential-cosinus function:
pretty(simplify(laplace((1-exp(-b*t/J))/b)))  %%%  Time function:
pretty(laplace(2*(1+t^2)*exp(5*t)))           %%%  Time function:
pretty(laplace(4+3*exp(-3*t)*sin(7*t)))       %%%  Time function:
pretty(laplace(2*exp(5*t)*sin(8*t)))          %%%  Time function:
pretty(laplace(2*t^2*exp(-4*t)))              %%%  Time function:
pause                           %%% Press a keybord key to continue 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%  "step" computes the step response of the given s function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
s=tf('s');                          %%% Defines "s" as the Laplace variable 
Gs=(3*s^2+5*s+2)/(s^3+4*s^2+3*s+1)  %%% Defines the Gs function:
figure(1)                           %%% Open a new figure
step(Gs)                            %%% Compute the step response of function Gs
grid on                             %%% Add the grid to the figure
                                    %%% See the figure. 
pause                           %%% Press a keybord key to continue 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Gs=(6*s+8)/(2*s+1)                  %%% Defines the Gs function:
figure(1)                           %%% Open a new figure
step(Gs)                            %%% Compute the step response of function Gs
grid on                             %%% Add the grid to the figure
ylim([0 10])                        %%% Defines the limits of the y axis 
%%% See the figure. 
pause                           %%% Press a keybord key to continue 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%  "ilaplace(Ys)" computes the inverse Laplace transform of function Ys
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
syms s t                            %%% Defines the symbolic variable s
Ys=(5*s+3)/((s+1)*(s+2)*(s+3))      %%% Defines the Ys function:
yt=ilaplace(Ys);                    %%% Inverse Laplace transform y(t):
pretty(yt)                          %%% Nice graphical representation
%%%%%%
Ys=(7*s^2-8*s+5)/(s^3+2*s^2+5*s)    %%% Defines the Ys function:
yt=ilaplace(Ys);                    %%% Inverse Laplace transform y(t):
pretty(yt)                          %%% Nice graphical representation
%%%%%%
Ys=1/(s+2)/(s+1)^2                  %%% Defines the Ys function:
yt=ilaplace(Ys);                    %%% Inverse Laplace transform y(t):
pretty(yt)                          %%% Nice graphical representation
pause                               %%% Press a keybord key to continue 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Two functions plotted on the same figure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(2); clf                      %%% Open a new figure
t=(0:0.01:1)*5;                     %%% Defines the time axis
yt=6*exp(-t).*(cos(2*t) - (4*sin(2*t))/3) + 1;  %%% Defines the y(t) function
y1t=1+10*exp(-t).*cos(2*t+atan(4/3));           %%% Defines the y1(t) function
plot(t,yt,'b')                      %%% Plot in blue the y(t) function
hold on                             %%% Mantains the previous plots
plot(t,y1t,'r.')                    %%% Plot in red the points of function y1(t)
grid on                             %%% Add the grid to the figure
pause                               %%% Press a keybord key to continue 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% The impulsive response is equal to the inverse Laplace transform
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
syms s t                            %%% Defines the symbolic variable s
Ys=(5*s+3)/((s+1)*(s+2)*(s+3))      %%% Defines the Ys function:
yt=ilaplace(Ys);                    %%% Inverse Laplace transform y(t):
%%%%%%
s=tf('s');                          %%% Defines "s" as the Laplace variable 
Y1s=(5*s+3)/((s+1)*(s+2)*(s+3))     %%% Defines the Ys function:
figure(3); clf                      %%% Open a new figure
impulse(Y1s)                        %%% Compute the impulse response of function Y1s
hold on                             %%% Mantains the previous plots
V=axis;                             %%% Read the ranges of the axis
t=(0:0.005:1)*V(2);                 %%% Defines the time axis
yt=eval(yt);                        %%% Defines the time axis
plot(t,yt,'r.')                     %%% Plot in red the points of function y1(t)
grid on                             %%% Add the grid to the figure
pause                               %%% Press a keybord key to continue 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Dominant poles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
syms s t                            %%% Defines the symbolic variable s
Ys=(s+37)*(s+225)/((s+350)*(10*s+15)*(s^2+2*s+20)*(40*s+2)*s);
yt=ilaplace(Ys)
y0=sym(111/2800);
y1=- (313*exp(-350*t))/16639696400880;
y2=(10579*exp(-(3*t)/2))/7782005;
y3=(111656197*exp(-t)*(cos(19^(1/2)*t) + (5150758*19^(1/2)*sin(19^(1/2)*t))/111656197))/746752945400;
y4=- (66495220*exp(-t/20))/1615852131;
figure(3); clf                      %%% Open a new figure
t=(0:0.002:1)*60;
plot(t,eval(yt),'r')
hold on
plot(t,eval(y0)+0*t,'m')
plot(t,eval(y1),'b')
plot(t,eval(y2),'b')
plot(t,eval(y3),'b')
plot(t,eval(y4),'m')
grid on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




