How to multiply function by the unit step function

조회 수: 20 (최근 30일)
Greg Boyle
Greg Boyle 2017년 2월 13일
답변: Star Strider 2017년 2월 13일
I am trying to multiply a function, f(t), by the unit step function, u(t), and consider the solution another function g(t), i.e. g(t)=f(t)*u(t) then plot as follows:
if true
%clear all
t=-10:0.05:20;
u(t>=0)=1;
f=inline('(exp(-.2*t).*sin(pi*t))','t');
g=inline('f(t).*u(t)','t');
figure(4)
plot(t,g(t))
grid
axis([-10 20 -1 1]);
ylabel('g(t)')
xlabel('Time (sec)')
title('g(t)=f(t)*u(t)')
hold off;
end
  댓글 수: 1
John BG
John BG 2017년 2월 13일
what operation do you want to apply; multiplication or convolution?

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2017년 2월 13일
I would use anonymous functions rather than inline functions (that will likely disappear in the not distant future).
This works:
t=-10:0.05:20;
u = @(t) +(t>=0); % Create A Function For ‘u(t)’
f = @(t) (exp(-.2*t).*sin(pi*t));
g = @(t) f(t).*u(t);
figure(4)
plot(t,g(t))
grid
axis([-10 20 -1 1]);
ylabel('g(t)')
xlabel('Time (sec)')
title('g(t)=f(t)*u(t)')
hold off;
My code for ‘u(t)’ uses your logical operator to create a series of logical true or 1, and putting a ‘+’ before it converts it from a series of logical 1 to double. (This is a little trick I learned from one of Stephen Cobeldick’s answers.)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by