How do I graph the Laplace transform of a function?

19 views (last 30 days)
So I've been working on this problem for a little while and I cannot seem to get past this one issue. The goal of the problem is to find the Laplace transform of a function and graph that Laplace transform on the same plot as the original function. I have a book for this class and I followed all of the instructions to a tee and I'm still getting an error when I try and run the code. If anyone could help me figure out my issue, that would be appreciated.
From Part A:
syms s t Y
% Defining the function h(t) with all of the necessary steps.
h = 1 + heaviside(t - pi)*(-1 - 1) + heaviside(t - 2*pi)*( 1 - (-1)) + ...
heaviside(t - 3*pi)*(-1 - 1) + heaviside(t - 4*pi)*(1 - (-1)) + ...
heaviside(t - 5*pi)*(-1 - 1) + heaviside(t - 6*pi)*(1 - (-1)) + ...
heaviside(t - 7*pi)*(-1 - 1) + heaviside(t - 8*pi)*(1 - (-1)) + ...
heaviside(t - 9*pi)*(-1 - 1) + heaviside(t - 10*pi)*(1 - (-1));
% Plotting the function h(t).
figure(1)
ezplot(h, [0 30])
title('Part A: h(t) on the interval [0, 30]')
xlim([0 30])
ylim([-2 2])
hold off
Part B:
syms s t Y
eqn = sym(['D(D(y))(t) + y(t) = ' h]);
lteqn = laplace(eqn, t, s);
neweqn = subs(lteqn, {'laplace(y(t), t, s)', 'y(0)', 'D(y)(0)'}, {Y, 0, 1});
ytrans = simplify(solve(neweqn, Y));
y = ilaplace(ytrans, s, t);
figure(2); hold on
%ezplot(y, [0 30])
ezplot(h, [0 30])
title('Part B: Laplace of h(t) on the interval [0, 30] w/ the graph of h(t)')
xlim([0 30])
ylim([-2 2])
hold off
The error that I am getting is "Error in sym/horzcat (line 14) args = privResolveArgs(varargin{:});". It goes away whenever I comment out all of the Laplace transform things, so the error is inside of those statements. The initial value problem that I am trying to solve is D^2(y) + y = h(t), y(0) = 0, y'(0) = 1. h(t) is supposed to be a square wave that goes from 1 to -1 for every value of pi and stays at that value until the next value of n*pi for 0 <= n <= 10.

Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!