How to multiply function by the unit step function
19 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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.)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!