0% found this document useful (0 votes)
41 views220 pages

Chapter 6 The Laplace Transform

This document contains MATLAB code that generates plots of various functions involving step functions and differential equations with discontinuous forcing functions. The plots demonstrate properties of step functions like jumps, periodicity, and convolution with other functions. They also show solutions to differential equations where the forcing function is discontinuous, such as including step functions.

Uploaded by

Filipe Tebas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views220 pages

Chapter 6 The Laplace Transform

This document contains MATLAB code that generates plots of various functions involving step functions and differential equations with discontinuous forcing functions. The plots demonstrate properties of step functions like jumps, periodicity, and convolution with other functions. They also show solutions to differential equations where the forcing function is discontinuous, such as including step functions.

Uploaded by

Filipe Tebas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 220

6.

1 The Laplace Transform

clear, clc
hold on
grid on
xlabel 't', ylabel 'f(t)'
t = 0:0.01:1;
plot(t,t.^2)
t = 1.01:0.01:2;
plot(t,2+t)
t = 2.01:0.01:3;
plot(t,6-t,'g')
legend('t^2','2+t','6-t', ...
'Location','northwest')

clear, clc
hold on
grid on
ylim([0 5]) % set vert axis range
xlabel 't', ylabel 'f(t)'
t = 0:0.01:1;
plot(t,t.^2)
t = 1.01:0.01:2;
plot(t,(t-1).^-1)
t = 2.01:0.01:3;
plot(t,t./t,'g')
legend('t^2','(t-1)^-1','1', ...
'Location','northwest')
clear, clc
hold on
grid on
ylim([0 1.5]) % set vert axis range
xlabel 't', ylabel 'f(t)'
t = 0:0.01:1;
plot(t,t.^2)
t = 1.01:0.01:2;
plot(t,t./t)
t = 2.01:0.01:3;
plot(t,3-t,'g')
legend('t^2','1','3-t', ...
'Location','northwest')
clear, clc
syms s a t
f = int(exp(-s*t)*t^2*sin(a*t),t);
collect(f, [cos(a*t) sin(a*t)])
6.2 Solution of Initial Value Problems

clear, clc
syms s
f = 2/(s^2 + 3*s -4)
partfrac(f)
clear, clc
syms s
f = (8*s^2 - 4*s + 12)/(s*(s^2 + 4))
partfrac(f)
clear, clc
syms s
f = (s-2)/((s-3)*(s+2))
partfrac(f)
clear, clc
syms s
f = (s+3)/((s+2)*(s+1))
partfrac(f)
clear, clc
syms s
factor(s^4 - 4*s^3 + 6*s^2 - 4*s +1)

clear, clc
syms s
f = (s^2 - 4*s + 7)/(s-1)^4
partfrac(f)
clear, clc
syms s
f = 1/((s+1)*(s^2 - 2*s + 2))
partfrac(f)
clear, clc
syms t
f(t) = sin(t)/t;
for n = 1:8
df=diff(f,t,n);
limit(df,t,0)
end
6.3 Step Functions

clear, clc
syms t g
g = heaviside(t-1) + ...
2*heaviside(t-3) - ...
6*heaviside(t-4);
fplot(g)
xlim([0 5]);
ylim([-4 4]);
grid on
title('g(t) = u1(t) + 2*u3(t) - 6*u4(t)')
xlabel 't', ylabel 'g(t)'
clear, clc
figure
hold on
xlim([0 5]);
ylim([-4 4]);
grid on

PlotHzLine(0,1,0) %initial part of u1


PlotHzLine(1,3,1) %u1 to next endpoint
PlotHzLine(3,4,3) %jump up 2 at next endpoint
PlotHzLine(4,9,-3) %jump down 6 at next endpoint

title('g(t) = u1(t) + 2*u3(t) - 6*u4(t)')


xlabel 't', ylabel 'g(t)'

function PlotHzLine(x1, x2, yvalue)


t = x1:0.01:x2-0.01;
plot(t,0*t + yvalue, '-b')
plot(x2,yvalue,'Marker',"o", "Color",'b')
end
clear, clc
figure
hold on
xlim([0 5]);
ylim([-1 5]);
grid on
t = 0:0.01:pi-0.01;
plot(t, 0*t) % plot 0
t= pi:0.01:5;
plot(t, (t-pi).^2)
title('g(t) = f(t-pi) * u_p_i(t), f(t) = t^2')
xlabel 't', ylabel 'g(t)'
clear, clc
figure
hold on
xlim([0 2*pi]);
ylim([-1.2 1.2]);
grid on
t = 0:0.01:3-0.01;
plot(t, 0*t) % plot 0
t= 3:0.01:2*pi;
plot(t, sin(t-3))
title('g(t) = f(t-3) * u_3(t), f(t) = sin(t)')
xlabel 't', ylabel 'g(t)'

clear, clc
figure
hold on
xlim([0 5]);
ylim([-1.2 1.2]);
grid on
t = 0:0.01:1-0.01;
plot(t, 0*t) % plot 0
t = 1:0.01:2-0.01;
plot(t, t-1) % t-1 on [1,2]
t = 2:0.01:3-0.01;
plot(t, (t-1) - 2*(t-2)) % on [2,3]
t = 3:0.01:5;
plot(t, (t-1) - 2*(t-2) + (t-3)) % on [3,5]
title('g(t) = (t-1)*u_1(t) - 2(t-2)*u_2(t) + (t-3)*u_3(t)')
xlabel 't', ylabel 'g(t)'
clear, clc
figure
hold on
x = [0, 9]; % xmin, xmax
xlim(x);
ylim([-3 3]);
grid on
int = [3, 5, 7]; % interval break points

t = 0:0.01:int(1)-0.01;
plot(t, 0*t) % plot 0
plot(int(1), 0, 'Marker',"o")

t = int(1):0.01:int(2)-0.01;
plot(t, 0*t - 2)
plot(int(2), -2, 'Marker',"o")

t = int(2):0.01:int(3)-0.01;
plot(t, 0*t + 2)
plot(int(3), 2, 'Marker',"o")

t = int(3):0.01:x(2);
plot(t, 0*t + 1)

xlabel 't', ylabel 'f(t)'


clear, clc
figure
hold on
x = [0, 5]; % xmin, xmax
xlim(x);
ylim([-2 2]);
grid on
int = [1, 2, 3, 4]; % interval breaks

t = 0:0.01:int(1)-0.01;
plot(t, 0*t + 1)
plot(int(1), 1, 'Marker',"o")

t = int(1):0.01:int(2)-0.01;
plot(t, 0*t - 1)
plot(int(2), -1, 'Marker',"o")

t = int(2):0.01:int(3)-0.01;
plot(t, 0*t + 1)
plot(int(3), 1, 'Marker',"o")

t = int(3):0.01:int(4)-0.01;
plot(t, 0*t - 1)
plot(int(4), -1, 'Marker',"o")

t = int(4):0.01:x(2);
plot(t, 0*t)

xlabel 't', ylabel 'f(t)'


clear, clc
figure
hold on
x = [0, 4]; % xmin, xmax
xlim(x);
ylim([0 2]);
grid on
int = [2]; % interval breaks

t = 0:0.01:int(1)-0.01;
plot(t, 0*t + 1)
%plot(int(1), 1, 'Marker',"o")

t = int(1):0.01:x(2);
plot(t, exp(-(t-2)))

xlabel 't', ylabel 'f(t)'


clear, clc
figure
hold on
x = [0, 9]; % xmin, xmax
xlim(x);
ylim([-1 3]);
grid on
int = [2, 5, 7]; % interval breaks

t = 0:0.01:int(1)-0.01;
plot(t, t)

t = int(1):0.01:int(2)-0.01;
plot(t, 0*t + 2)

t = int(2):0.01:int(3)-0.01;
plot(t, 7 - t)

t = int(3):0.01:x(2);
plot(t, 0*t)

xlabel 't', ylabel 'f(t)'


clear, clc
syms s
partfrac(1/(s^2 + s - 2))
clear, clc
figure
hold on
xlim([0 3]);
ylim([-1 2]);
grid on

PlotHzLine(0,1,1) %initial part of u1


PlotHzLine(1,5,0) %u1 to next endpoint

title('f(t) = 1 - u_1(t)')
xlabel 't', ylabel 'f(t)'

function PlotHzLine(x1, x2, yvalue)


t = x1:0.01:x2-0.01;
plot(t,0*t + yvalue, '-b')
plot(x2,yvalue,'Marker',"o", "Color",'b')
end
clear, clc
t = 0:0.01:1;
plot(t, t)
hold on
t = 1:0.01:3;
plot(t, 0*t + 1)
xlim([0 3]);
ylim([-1 2]);
grid on
title('g(t) = t, [0,1), 1 [1,...]')
xlabel 't', ylabel 'g(t)'
clear, clc
syms t g h
g(t) = t - (t-1)*heaviside(t-1);
h = g(t) - g(t-1)*heaviside(t-1);
fplot(h)
xlim([0 3]);
ylim([-1 2]);
grid on
title('h(t) = g(t) - u_1(t)*g(t-1)')
xlabel 't', ylabel 'h(t)'
clear, clc
figure
hold on
xlim([0 8]);
ylim([-1 2]);
grid on
for i = 0:2:6
PlotSawtooth(i)
end
title('p(t) = t [0,1), 2-t [1,2) p(t+2) = p(t)')
xlabel 't', ylabel 'p(t)'

function PlotSawtooth(x)
t = x:0.01:x+1; % [0,1]
plot(t, t-x, '-b') % subtract x start value
t = x+1:0.01:x+2; % [1,2]
plot(t, 2-(t-x), 'b')
end
6.4 Differential Equations with Discontinuous Forcing Functions

clear, clc
figure
hold on
xlim([0 14]);
ylim([-0.5 1.5]);
grid on

PlotHzLine(0,3*pi,1) %initial part of u1


PlotHzLine(3*pi,15,0) %u1 to next endpoint

title('f(t) = u_0(t) - u_3_p_i(t)')


xlabel 't', ylabel 'f(t)'

function PlotHzLine(x1, x2, yvalue)


t = x1:0.01:x2-0.01;
plot(t,0*t + yvalue, '-b')
plot(x2,yvalue,'Marker',"o", "Color",'b')
end
clear, clc
syms t
y(t) = 1 + sin(t) - cos(t) - heaviside(t-3*pi)*(1 + cos(t));
fplot(y(t), [0,30])
grid on
ylim([-3, 3])
xlabel 't', ylabel 'y(t)'
title 'y(t) = 1 + sin(t) - cos(t) - u_3_p_i*(1 + cos(t))'
clear, clc
figure
hold on
xlim([0 14]);
ylim([-0.5 1.5]);
grid on

PlotHzLine(0,pi,0)
PlotHzLine(pi,2*pi,1)
PlotHzLine(2*pi,15,0)

title('h(t) = u_p_i(t) - u_2_p_i(t)')


xlabel 't', ylabel 'h(t)'

function PlotHzLine(x1, x2, yvalue)


t = x1:0.01:x2-0.01;
plot(t,0*t + yvalue, '-b')
plot(x2,yvalue,'Marker',"o", "Color",'b')
end
clear, clc
syms t
y(t) = exp(-t)*sin(t) + ...
(1/2)*heaviside(t-pi)*(1 + exp(pi-t)*(cos(t) + sin(t))) - ...
(1/2)*heaviside(t-2*pi)*(1 - exp(2*pi-t)*(cos(t) + sin(t)));
fplot(y(t), [0,12])
grid on
ylim([-0.3, 0.8])
xlabel 't', ylabel 'y(t)'
title 'Solution to D_2y + 2D_1y + 2y = h(t)'
clear, clc
syms t
f(t) = sin(t) - heaviside(t-2*pi)*sin(t);
fplot(f)
xlim([0 4*pi]);
ylim([-1.5 1.5]);
grid on
title('h(t) = sin(t) - u_2_p_i(t)*sin(t)')
xlabel 't', ylabel 'f(t)'
clear, clc
syms t
y(t) = (1/6)*(1 - heaviside(t-2*pi))*(2*sin(t) - sin(2*t));
fplot(y(t), [0, 4*pi])
grid on
ylim([-0.5, 0.5])
xlabel 't', ylabel 'y(t)'
title 'y(t) = (1/6)[1 - u_2_p_i(t)] * [2*sin(t) - sin(2*t)]'
clear, clc
figure
hold on
xlim([0 14]);
ylim([-0.5 1.5]);
grid on

PlotHzLine(0,10,1)
PlotHzLine(10,15,0)

title('f(t) = 1 - u_1_0(t)')
xlabel 't', ylabel 'f(t)'

function PlotHzLine(x1, x2, yvalue)


t = x1:0.01:x2-0.01;
plot(t,0*t + yvalue, '-b')
plot(x2,yvalue,'Marker',"o", "Color",'b')
end
clear, clc
syms s
d = s*(s+2)*(s+1);
partfrac(1/d)

clear, clc
syms t
g(t) = 1/2 + (1/2)*exp(-2*t) - exp(-t);
y(t) = g(t) - heaviside(t-10)*g(t-10);
fplot(y(t), [0, 20])
grid on
ylim([-0.2, 0.8])
xlabel 't', ylabel 'y(t)'
title 'Solution to D_2y + 3D_1y +2y = f(t)'
clear, clc
syms t
f(t) = t - heaviside(t - pi/2)*(t - pi/2);
fplot(f(t), [0, 4])
grid on
ylim([-0.2, 2])
xlabel 't', ylabel 'f(t)'
title 't - u_p_i_/_2(t - pi/2)'

clear, clc
syms s
d = s^2*((s+1/2)^2 + 1)
partfrac(1/d)
clear, clc
syms t
g(t) = -16/25 + (4/5)*t + (1/25)*(exp(-t/2))*(16*cos(t)-12*sin(t));
y(t) = g(t) - heaviside(t - pi/2)*g(t - pi/2);
fplot(y(t), [0, 20])
grid on
ylim([-0.2, 2])
xlabel 't', ylabel 'y(t)'
title 'Solution to D_2y + D_1y + 5/4y = t - u_p_i_/_2(t) (t - pi/2)'
clear, clc
syms t
g(t) = sin(t) + heaviside(t-pi)*sin(t-pi);
fplot(g(t), [0, 3*pi])
grid on
ylim([-0.2, 1.2])
xlabel 't', ylabel 'g(t)'
title 'sin(t) - u_p_i(t-pi)*sin(t-pi)'
clear, clc
syms s
d = (s^2 + 1)*((s+1/2)^2 + 1)
partfrac(1/d)
clear, clc
syms t
h(t) = (4/17)*(-4*cos(t) + sin(t) + ...
4*exp(-t/2)*cos(t) + exp(-t/2)*sin(t));
y(t) = h(t) + heaviside(t-pi)*h(t-pi);
fplot(y(t), [0, 20])
grid on
ylim([-0.2, 1])
xlabel 't', ylabel 'y(t)'
title 'Solution to D_2y + D_1y + 5/4y = sin(t) + u_p_i(t) sin(t - pi)'
clear, clc
figure
hold on
xlim([0 14]);
ylim([-0.5 1.5]);
grid on

PlotHzLine(0,pi,0)
PlotHzLine(pi,3*pi,1)
PlotHzLine(3*pi,15,0)

title('f(t) = u_p_i(t) - u_3_p_i(t)')


xlabel 't', ylabel 'f(t)'

function PlotHzLine(x1, x2, yvalue)


t = x1:0.01:x2-0.01;
plot(t,0*t + yvalue, '-b')
plot(x2,yvalue,'Marker',"o", "Color",'b')
end
clear, clc
syms t
y(t) = (1/4)*heaviside(t-pi)*(1-cos(2*t)) - ...
(1/4)*heaviside(t-3*pi)*(1-cos(2*t));
fplot(y(t), [0, 20])
grid on
ylim([-0.2, 1])
xlabel 't', ylabel 'y(t)'
title '(1/4)u_p_i(1-cos(2t)) - (1/4)u_3_p_i(1-cos(2t))'
clear, clc
figure
hold on
xlim([0 2*pi]);
ylim([-0.5 1.5]);
grid on

PlotHzLine(0,pi,1)
PlotHzLine(pi,10,0)

title('f(t) = 1 - u_p_i(t)')
xlabel 't', ylabel 'f(t)'

function PlotHzLine(x1, x2, yvalue)


t = x1:0.01:x2-0.01;
plot(t,0*t + yvalue, '-b')
plot(x2,yvalue,'Marker',"o", "Color",'b')
end
clear, clc
syms s
d = s*(s^2 + 4)*(s^2 + 1);
partfrac(1/d)
clear, clc
syms t
y(t) = 1/4 - (1/3)*cos(t) + (1/12)*cos(2*t) - ...
heaviside(t-pi)*(1/4 + (1/3)*cos(t) + (1/12)*cos(2*t));
fplot(y(t), [0, 4*pi])
grid on
ylim([-1, 1])
xlabel 't', ylabel 'y(t)'
title 'Solution to D_4y + 5D_2y + 4y = 1 - u_p_i(t)'
clear, clc
syms t
h = 4; k = 3; t0= 2; % example values
f(t) = heaviside(t-t0)*(h/k)*(t-t0) - ...
heaviside(t-t0-k)*(h/k)*(t-t0-k);
fplot(f(t), [0, 10])
ylim([-0.2, h + 0.2])
grid on
clear, clc
syms t
h = 4; k = 3; t0= 2; % example values
f1(t) = (h/k)*(t-t0)*(heaviside(t-t0) - heaviside(t-(t0+k)));
f2(t) = ((-h/k)*(t-t0-k)+h)*(heaviside(t-(t0+k)) - heaviside(t-(t0+2*k)));
fplot(f1(t)+f2(t), [0, 10])
ylim([-0.2, h + 0.2])
grid on
clear, clc
figure
hold on
xlim([0 4]);
ylim([-0.5 1.5]);
grid on

PlotHzLine(0,3/2,0)
PlotHzLine(3/2,5/2,1)
PlotHzLine(5/2,15,0)

title('g(t) = u_3_/_2(t) - u_5_/_2(t)')


xlabel 't', ylabel 'g(t)'

function PlotHzLine(x1, x2, yvalue)


t = x1:0.01:x2-0.01;
plot(t,0*t + yvalue, '-b')
plot(x2,yvalue,'Marker',"o", "Color",'b')
end
clear, clc
syms t
a = 3*sqrt(7)/8; b = sqrt(7)/21; % constants
h(t) = 1 - exp(-t/8)*(cos(a*t) + b*sin(a*t));
fplot(heaviside(t-3/2) - heaviside(t-5/2)) % the impulse
hold on
for k = [1/2 1 2]
y(t) = k*heaviside(t-3/2)*h(t-3/2) - ...
k*heaviside(t-5/2)*h(t-5/2);
fplot(y(t))
end
grid on
xlim([0 30]), ylim([-2 2])
xlabel 't', ylabel 'u(t)'
title(['Solution to ' ...
'u" + (1/4)u'' + u = k[u_3_/_2(t) - u_5_/_2(t)], '...
'k = 1/2, 1, 2'])
legend('impulse', 'k = 1/2', 'k = 1', 'k = 2')
clear, clc
t = 0:0.001:5;
a = 3*sqrt(7)/8; b = sqrt(7)/21; % constants
c3 = 3/2; c5 = 5/2;
%h(t) = 1 - exp(-t/8).*(cos(a*t) + b*sin(a*t));
% loop through computations until get y(t) > 2.0
for k = 2:0.01:3
h3 = 1 - exp(-(t-c3)/8).*(cos(a*(t-c3)) + b*sin(a*(t-c3)));
h5 = 1 - exp(-(t-c5)/8).*(cos(a*(t-c5)) + b*sin(a*(t-c5)));
y = k*heaviside(t-c3).*h3 - ...
k*heaviside(t-c5).*h5;
if max(y) > 2
break
end
end
maxk = num2str(k); % the k that gives y(t) > 2.0
maxy = num2str(max(y)); % the value of y at maxk
plot(t, y)
hold on
plot(t,k*heaviside(t-c3) - k*heaviside(t-c5)) % the impulse
grid on
xlim([0 5]), ylim([-0.2 k + 0.2])
xlabel 't', ylabel 'u(t)'
str = 'Solution to u" + (1/4)u'' + u = k(u_3_/_2(t) - u_5_/_2(t)), k = ';
title(strcat(str,maxk))
str = strcat('max y = ', maxy);
legend(str, 'impulse')
clear, clc
tmax = 30; %local max seems < 0.1 at t 0 30 ses
mesh = 100000;
t = 0:1/mesh:tmax;
a = 3*sqrt(7)/8; b = sqrt(7)/21; % constants
c3 = 3/2; c5 = 5/2;
k = 2;
%h(t) = 1 - exp(-t/8).*(cos(a*t) + b*sin(a*t));
h3 = 1 - exp(-(t-c3)/8).*(cos(a*(t-c3)) + b*sin(a*(t-c3)));
h5 = 1 - exp(-(t-c5)/8).*(cos(a*(t-c5)) + b*sin(a*(t-c5)));
% load the plot values - take absolute value
y = abs(k*heaviside(t-c3).*h3 - ...
k*heaviside(t-c5).*h5);
plot(t, y)
grid on, grid minor
xlim([0, tmax]), ylim([-0.2, k])
xlabel 't', ylabel 'u(t)'
str = 'Solution to u" + (1/4)u'' + u = k[u_3_/_2(t) - u_5_/_2(t)], k = ';
title(strcat(str,num2str(2)))

format long % display answers to 15 decimals


indexMax = tmax*mesh + 1; % MATLAB arrays are 1-based
for i = indexMax:-1:1
if y(i)> 0.1
maxIndex = i;
break
end
end
tau = (maxIndex-1)/mesh
y(maxIndex), y(maxIndex + 1) % show values at and after tau
clear, clc
t = 500:0.1:500+4*pi;
figure
hold on
for k = [1,2,3]
amp = 1/(8*k);
y = 1/4 - amp*(sin(2*t-10) - sin(2*t-10-2*k));
plot(t, y)
end
grid on
grid minor
xlabel 't', ylabel 'y'
title 'plot of y(t) for large t'
legend('k=1', 'k=2', 'k=3')
clear, clc
syms t f
f = heaviside(t);
for k = 1:6
f = f + 2*(-1)^k*heaviside(t-k*pi);
end
hold on
fplot(f)
fplot(0)
ylim([-1.5, 1.5])
xlim([0, 6*pi])
grid on
xlabel 't', ylabel 'f(t)'
clear, clc
n = 15; tmax = 60;
t = 0:0.01:tmax;
y = 1 - cos(t);
for k = 1:n
y = y + 2*(-1)^k*heaviside(t-k*pi).*(1 - cos(t-k*pi));
end
plot(t, y)
grid on
xlim([0, tmax])
xlabel 't', ylabel 'y(t)'
title('y" + y = f(t)')
clear, clc
syms t
n = 40; tmax = n*pi + 100;
c = 0.05; w = sqrt(0.9975);
d = -atan(c/w);
h(t) = 1 - exp(-c*t)*((1/w)*cos(w*t - d));
y(t) = h(t);
for k = 1:n
y(t) = y(t) + 2*(-1)^k*heaviside(t-k*pi)*h(t-k*pi);
end
fplot(y(t))
hold on
fplot(h(t))
xlim([0,tmax])
ylim([-15, 15])
grid on, grid minor
xlabel 't', ylabel 'y(t)'
title 'Solution to y" + 0.1y'' + y = f(t), y(0) = 0, y''(0) = 0')
legend('y(t)', 'h(t)')
clear, clc
syms t g
g = heaviside(t); % u0(t)
for k = 1:6
g = g + (-1)^k*heaviside(t-k*pi);
end
hold on
fplot(g)
ylim([-0.25, 1.5])
xlim([0, 6.5*pi])
grid on
xlabel 't', ylabel 'g(t)'
clear, clc
n = 15; tmax = 80;
t = 0:0.01:tmax;
y = 1 - cos(t);
for k = 1:n
y = y + (-1)^k*heaviside(t-k*pi).*(1 - cos(t-k*pi));
end
plot(t, y)
hold on
xline(n*pi,'Color', 'r', 'LineWidth', 0.75); % forcing ends
grid on
xlim([0, tmax])
xlabel 't', ylabel 'y(t)'
title('y" + y = g(t)')
legend('y(t)', 'forcing ends', 'location', "northwest")
clear, clc
syms t
n = 40; tmax = n*pi + 100;
c = 0.05; w = sqrt(0.9975);
d = -atan(c/w);
h(t) = 1 - exp(-c*t)*((1/w)*cos(w*t - d));
y(t) = h(t);
for k = 1:n
y(t) = y(t) + (-1)^k*heaviside(t-k*pi)*h(t-k*pi);
end
fplot(y(t))
hold on
fplot(h(t))
xline(35*pi, 'color', 'g'); % vertical line at t = 35*pi
xline(37*pi, 'color', 'g'); % vertical line at t = 37*pi
xlim([0,tmax])
ylim([-8, 8])
grid on, grid minor
xlabel 't', ylabel 'y(t)'
title 'Solution to y" + 0.1y'' + y = g(t), y(0) = 0, y''(0) = 0')
legend('y(t)', 'h(t)')
clear, clc
n = 35; f = 11/4; tmax = n*f + 25;
t = 0:0.01:tmax;
y = 1 - cos(t);
for k = 1:n
y = y + (-1)^k*heaviside(t-k*f).*(1 - cos(t-k*f));
end
plot(t, y)
hold on
xline(n*f,'Color', 'r', 'LineWidth', 0.75); % forcing ends
grid on, grid minor
xlim([0, tmax])
xlabel 't', ylabel 'y(t)'
title('y" + y = h(t) n = 35')
legend('h(t)', 'forcing ends', 'location', "southwest")
clear, clc
syms t
f = 11/4;
h = heaviside(t); % u0(t)
for k = 1:4
h = h + 2*(-1)^k*heaviside(t-k*f);
end
hold on
fplot(h)
yline(0); % horizontal line y = 0
ylim([-1.5, 1.5])
xlim([0, 4.5*f])
grid on, grid minor
xlabel 't', ylabel 'h(t)'
6.5 Impulse Functions

clear, clc
syms t
f = exp(-t)*(cos(t) + sin(t)) + ...
heaviside(t-pi)*exp(pi-t)*sin(t-pi);
fplot(f, [0,4*pi])
ylim([-0.1, 1.1])
hold on
xline(pi, 'color', 'r'); % show the impulse
grid on
xlabel('t'), ylabel('y(t)')
title('y" + 2y'' + 2y = delta(t-pi), y(0)=1, y''(0)=0')
clear, clc
syms t
f = (1/2)*heaviside(t-pi)*sin(2*t) - ...
(1/2)*heaviside(t-2*pi)*sin(2*t);
fplot(f, [0,3*pi])
ylim([-0.6, 0.6])
hold on
xline(pi, 'color', 'r'); % show the impulse
xline(2*pi, 'color', 'r');
grid on
xlabel('t'), ylabel('y(t)')
title('y" + 4y = delta(t-pi)-delta(t-2*pi), y(0)=0, y''(0)=0')
clear, clc
syms s
d = s*(s+2)*(s+1);
partfrac(1/d)
clear, clc
syms t
f = (1/2)*(exp(-t) - exp(-2*t)) + ...
heaviside(t-5)*(exp(-(t-5)) - exp(-2*(t-5))) + ...
heaviside(t-10)*(-exp(-(t-10)) + (1/2)*exp(-2*(t-10)) + 1/2);
fplot(f, [0,20])
ylim([-0.1, 0.6])
hold on
xline(5, 'color', 'r'); % show the impulse
xline(10, 'color', 'r');
grid on
xlabel('t'), ylabel('y(t)')
title('y" + 3y'' + 2y = delta(t-5) + u_1_0(t), y(0)=0, y''(0)=1/2')
clear, clc
syms s
d = (s^2 + 1)*(s^2 + 2*s + 3);
partfrac(1/d)

clear, clc
syms t
a = sqrt(2);
f = (1/4)*(exp(-t)*cos(a*t) - cos(t) + sin(t)) ...
+(1/a)*heaviside(t-3*pi)*exp(3*pi-t)*sin(a*(t-3*pi));
fplot(f, [0,6*pi])
ylim([-0.6, 0.6])
hold on
xline(3*pi, 'color', 'r'); % show the impulse
grid on
xlabel('t'), ylabel('y(t)')
title('y" + 2y'' + 3y = sin(t) + delta(t-3*pi), y(0)=0, y''(0)=0')
legend('y(t)', 'impulse')
clear, clc
syms t
f = sin(t) + heaviside(t-2*pi)*sin(t);
fplot(f, [0,6*pi])
ylim([-2.1, 2.1])
hold on
xline(2*pi, 'color', 'r'); % show the impulse
grid on
xlabel('t'), ylabel('y(t)')
title('y" + y'' = delta(t-2*pi)cos(t), y(0)=0, y''(0)=1')
legend('y(t)', 'impulse', 'location', "southwest")
clear, clc
syms t
f = -heaviside(t-pi/4)*cos(2*t);
fplot(f, [0,3*pi])
ylim([-1.5, 1.5])
hold on
xline(pi/4, 'color', 'r'); % show the impulse
grid on
xlabel('t'), ylabel('y(t)')
title('y" + y'' = -u_p_i_/_4(t)cos(2t), y(0)=0, y''(0)=0')
legend('y(t)', 'impulse')
clear, clc
syms s
d = (s^2 + 1)*(s^2 + 2*s + 2);
partfrac(s/d)
clear, clc
syms t
f = (1/5)*(cos(t) + 2*sin(t)) ...
- (1/5)*exp(-t)*(cos(t) + 3*sin(t)) ...
+ heaviside(t-pi/2)*exp(pi/2 - t)*sin(t-pi/2);
fplot(f, [0,4*pi])
ylim([-0.8, 0.8])
hold on
xline(pi/2, 'color', 'r'); % show the impulse
grid on
xlabel('t'), ylabel('y(t)')
title('y" + 2y'' + 2y = cos(t) + delta(t-pi/2), y(0)=0, y''(0)=0')
legend('y(t)', 'impulse')
clear, clc
syms t
f = (1/2)*heaviside(t-1)*(sinh(t-1) - sin(t-1));
fplot(f, [0,6])
ylim([-0.2, 10])
hold on
xline(1, 'color', 'r'); % show the impulse
grid on
xlabel('t'), ylabel('y(t)')
title('y"" - y = delta(t-1), y(0)=0, y''(0)=0, y"(0)=0, y(0)"''=0')
legend('y(t)', 'impulse', 'location', "southeast")
clear, clc
syms t
a = sqrt(15)/4;
t0 = 5 + 2*pi/a;
k = -exp(-2*pi/sqrt(15));
f(t) = (1/a)*exp(-t/4)*sin(a*t);
y = (1/2)*heaviside(t-5)*f(t-5) + (k/2)*heaviside(t-t0)*f(t-t0);
fplot(y, [0,2*t0-5])
ylim([-0.3, 0.5])
hold on
xline(5, 'color', 'r'); % show the impulses
xline(t0, 'color', 'r');
grid on
xlabel('t'), ylabel('y(t)')
title('2y" + y'' + 2y = delta(t-5) + k*delta(t-t0), y(0)=0, y''(0)=0')
legend('y(t)', 'impulses')
clear, clc
syms t
a = sqrt(15)/4;
y = (1/a)*heaviside(t-1)*exp(-(t-1)/4)*sin(a*(t-1));
fplot(y, [0, 1+5*pi])
ylim([-1, 1])
hold on
xline(1, 'color', 'r'); % show the impulse
grid on
xlabel('t'), ylabel('y(t)')
title('y" + 1/2y'' + y = delta(t-1), y(0)=0, y''(0)=0')
legend('y(t)', 'impulse')
clear, clc
tmesh = 0.0001; % indicate precision of times
t = 0:tmesh:5*pi; %create an array of times
a = sqrt(15)/4;
y = (1/a)*heaviside(t-1).*exp(-(t-1)/4).*sin(a*(t-1));
plot(t, y)
xlim([0,5*pi])
ylim([-1, 1])
hold on
xline(1, 'color', 'r'); % show the impulse
grid on
xlabel('t'), ylabel('y(t)')
title('y" + 1/2y'' + y = delta(t-1), y(0)=0, y''(0)=0')
legend('y(t)', 'impulse')
[ymax,tindex] = max(y)
tmax = (tindex-1)*tmesh % arrays are 1-based
clear, clc
tmesh = 0.0001; % indicate precision of times
t = 0:tmesh:6*pi; % create an array of times
a = 3*sqrt(7)/8;
y = (1/a)*heaviside(t-1).*exp(-(t-1)/8).*sin(a*(t-1));
plot(t, y)
xlim([0,6*pi])
ylim([-1, 1])
hold on
xline(1, 'color', 'r'); % show the impulse
grid on
xlabel('t'), ylabel('y(t)')
title('y" + 1/4y'' + y = delta(t-1), y(0)=0, y''(0)=0')
legend('y(t)', 'impulse')
[ymax,tindex] = max(y)
tmax = (tindex-1)*tmesh % arrays are 1-based
clear, clc
syms t
k = 0.25;
f = (1/(2*k)*(heaviside(t-(4-k))-heaviside(t-(4+k))));
fplot(f, [0,6])
ylim([-0.2, 2.2])
grid on
xlabel 't', ylabel 'f(t)'
title 'f(t) = 1/2k[u_4_-_k(t) - u_4_+_k(t)]'
clear, clc
syms t
phi0 = heaviside(t-4)*sin(t-4);
fplot(phi0)
hold on
h(t) = 1 - cos(t);
for k = [1/2, 1/4]
t1 = t - (4-k);
t2 = t - (4+k);
c = 1/(2*k);
phi = c*(heaviside(t1)*h(t1) - heaviside(t2)*h(t2));
fplot(phi)
end
xlim([0, 4 + 2.6*pi])
ylim([-1.1, 1.1])
grid on
xlabel 't', ylabel 'phi(t,k)'
title 'y" + y = 1/2k[u_4_-_k(t) - u_4_+_k(t)], y(0)=0, y''(0)=0'
legend('phi0(t)', 'phi(t, 1/2)', 'phi(t, 1/4)', 'location', "southwest")
clear, clc
syms t y
figure
hold on
y = 0;
for k = 1:20
y = y + heaviside(t-k*pi)*sin(t-k*pi);
xline(k*pi, 'color', 'r'); % show impulses
end
fplot(y)
xlim([0, 22*pi])
ylim([-0.2, 1.1])
grid on
xlabel 't', ylabel 'y(t)'
title 'y" + y = Sigma(delta(t-k*pi), y(0)=0, y''(0)=0'
legend('impulses', 'location', "southeast")
clear, clc
syms t y
y = 0;
for k = 1:20
y = y + ((-1)^(k+1))*heaviside(t-k*pi)*sin(t-k*pi);
end
fplot(y, [0, 24*pi])
ylim([-21, 21])
grid on
xlabel 't', ylabel 'y(t)'
title 'y" + y = Sigma((-1)^(^k^+^1^)delta(t-k*pi)), y(0)=0, y''(0)=0'
clear, clc
syms t y
y = 0;
for k = 1:15
y = y + heaviside(t-(2*k-1)*pi)*sin(t-(2*k-1)*pi);
end
fplot(y, [0, 32*pi])
ylim([-17, 17])
grid on
xlabel 't', ylabel 'y(t)'
title 'y" + y = Sigma(delta(t-(2k-1)*pi)), y(0)=0, y''(0)=0'
clear, clc
syms t y
y = 0; a = 11/4;
for k = 1:40
y = y + ((-1)^(k+1))*heaviside(t-a*k)*sin(t-a*k);
end
fplot(y, [0, 125])
ylim([-7, 7])
grid on
xlabel 't', ylabel 'y(t)'
title 'y" + y = Sigma((-1)^(^k^+^1^)delta(t-(11/4)k)), y(0)=0, y''(0)=0'
clear, clc
syms t y
y = 0; a = sqrt(399)/20;
h(t) = (1/a)*heaviside(t)*exp(-t/20)*sin(a*t);
for k = 1:20
y = y + ((-1)^(k+1))*h(t-k*pi);
end
fplot(y, [0, 38*pi])
ylim([-8, 8])
grid on
xlabel 't', ylabel 'y(t)'
title 'y" + 0.1y'' + y = Sigma((-1)^(^k^+^1^)delta(t-k*pi)), y(0)=0, y''(0)=0'
clear, clc
syms t y
y = 0; a = sqrt(399)/20;
h(t) = (1/a)*heaviside(t)*exp(-t/20)*sin(a*t);
for k = 1:15
y = y + h(t-(2*k-1)*pi);
end
fplot(y, [0, 50*pi])
ylim([-4, 4])
grid on
xlabel 't', ylabel 'y(t)'
title 'y" + 0.1y'' + y = Sigma(delta(t-(2k-1)*pi)), y(0)=0, y''(0)=0'
6.6 The Convolution Integral
clear, clc
syms s
d = s^4 + 5*s^2 + 4;
partfrac((s^3 + 5*s)/d)
clear, clc
syms s
d = (s^2 + 1)*(s^2 + 4);
partfrac(2*s^2/d)
clear, clc
syms s
d = (s+1)^3;
partfrac((s^2 + 1)/d)
clear, clc
syms s
d = (s+1)^2;
partfrac((s - 1)/d)
clear, clc
syms s
d = s^3 + 1;
partfrac(1/d)
clear, clc
a = 5; % arbitrarily assigned
th = 0:0.01:pi;
x = a*(th + sin(th));
y = a*(1 - cos(th));
plot(x,y)
grid on
xlabel 'x', ylabel 'y'

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy