Generating and plotting functions.
6 ビュー (過去 30 日間)
古いコメントを表示
I just started picking up MATLAB and I've been trying to generate these signals for a while.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/471227/image.jpeg)
This is what ive attempted so far:
t=[-1:0.1:3];
y=exp(-t/3);
plot(t,y)
Help would be greatly appreciated.
2 件のコメント
Ameer Hamza
2020 年 12 月 26 日
Can you show what have you already tried? https://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
回答 (2 件)
Ameer Hamza
2020 年 12 月 26 日
The exponent also contain abs() function. You can write it like this
t = -1:0.1:3;
y = exp(-abs(t)/5);
plot(t,y)
Also, the u(), the unit step function can be defined like this
u = @(x) (u>=0)*1;
So for an arbitrary range of t values, following will work
u = @(x) (x>=0)*1;
t = -5:0.1:5;
y = exp(-abs(t)/5).*(u(t+1)-u(t-3));
plot(t,y)
0 件のコメント
Image Analyst
2020 年 12 月 26 日
You can use linspace() and then logical indexing to move the step function to the correct location. Then combine. Here's a hint:
numElements = 1000; % Arbitrary - Most of the pixels across the screen.
% Make t axis.
t = linspace(-10, 10, numElements);
% Make step function that goes from 0 to 1 at t=0.
u = ones(1, numElements);
u1 = u;
% Make shifted step function that goes from 0 to 1 at t=-1.
% Zero out u uptil t == -1
u1(t < -1) = 0;
subplot(3, 1, 1);
plot(t, u1, 'b-', 'LineWidth', 2);
grid on;
title('u(t + 1)', 'FontSize', 20);
xlabel('t', 'FontSize', 20);
% Make shifted step function that goes from 0 to 1 at t=3.
u2 = u;
% Zero out u uptil t == 3
u2(t < 3) = 0;
subplot(3, 1, 2);
plot(t, u2, 'b-', 'LineWidth', 2);
grid on;
title('u(t - 3)', 'FontSize', 20);
xlabel('t', 'FontSize', 20);
y = % See if you can do this with abs() and dot star to to element by element multiplication
% Should be something times something minus something times something.
subplot(3, 1, 3);
plot(t, y, 'b-', 'LineWidth', 2);
grid on;
title('y(t)', 'FontSize', 20);
xlabel('t', 'FontSize', 20);
% Maximize figure window.
g = gcf;
g.WindowState = 'maximized'
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/471292/image.png)
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!