How to multiply function by the unit step function
19 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Risposte (1)
Star Strider
il 13 Feb 2017
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 Commenti
Vedere anche
Categorie
Scopri di più su Graphics Performance in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!