integral of two added function can't be implemented

1 view (last 30 days)
im trying to answer q5 here
%Q4 answer
clc
clear
u = @(t) double(t>=0);
h = @(t) exp(-t).*(u(t)-u(t-1));
h1= @(t) u(t)-2.*u(t-1)+u(t-2)
h1 = function_handle with value:
@(t)u(t)-2.*u(t-1)+u(t-2)
h2= @(t) h(t) + h1(t)
h2 = function_handle with value:
@(t)h(t)+h1(t)
fplot(h2,[-3,3])
grid on
ylim([-1 2])
% Q5 answer
clc
clear
t=@(t) t
t = function_handle with value:
@(t)t
u = @(t) double(t>=0);
h = @(t) exp(-t).*(u(t)-u(t-1));
h1= @(t) u(t)-2.*u(t-1)+u(t-2)
h1 = function_handle with value:
@(t)u(t)-2.*u(t-1)+u(t-2)
h2= @(t) h(t) + h1(t)
h2 = function_handle with value:
@(t)h(t)+h1(t)
i=integral(h2,-inf,t)
Error using integral
Limits of integration must be double or single scalars.
fplot(i,[-3,3])
grid on
ylim([-1 2])

Answers (1)

Paul
Paul on 28 Oct 2022
Hi Faisal,
If the plot for the answer to Q4 is corret, then does the integration really need to start from -inf?
However, I suggest revisiting Q4, that solution does not look correct. Why would the output of the system be the sum of the impulse response and the input?
  16 Comments
Faisal Al-Wazir
Faisal Al-Wazir on 5 Nov 2022
Edited: Faisal Al-Wazir on 5 Nov 2022
greetings paul
i reviewed the code that we were discussing and i think the values you were using are differnt then mine
%%
%q4
clc
clear
u = @(t) double(t >= 0); % unit step
h = @(t) exp(-t).*(u(t) - u(t-2)); % impulse response
x = @(t) u(t-1)-2*u(t-2)+u(t-3); % input
y = @(t,dt) conv(h(t),x(t))*dt; % output, scaled by dt to convert from sum to integral
tval = 0:.001:5;
dt = tval(2);
yval = y(tval,dt);
yval = yval(1:numel(tval)); % only retain as many points as in t
plot(tval,yval)
%%
%q5
tval = 0:.001:3;
yval = conv(h(tval),x(tval))*dt;
yval = yval(1:numel(tval));
plot(tval,cumtrapz(tval,yval))
Paul
Paul on 5 Nov 2022
Yes, as I stated previously, I was showing an example that would have to be modified for the specific problem at hand.
Your current code changes the definition of x(t) from the original Q4. For Q5, consider extending tval to a longer time.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!