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!