# Generating and plotting functions.

4 ビュー (過去 30 日間)
mar gal 2020 年 12 月 26 日

I just started picking up MATLAB and I've been trying to generate these signals for a while.
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 件のコメント表示非表示 1 件の古いコメント
mar gal 2020 年 12 月 26 日
t=[-1:0.1:3];
y=exp(-t/3);
plot(t,y)
That's what I have attempted in part a

サインインしてコメントする。

### 回答 (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 件のコメント表示非表示 -1 件の古いコメント

サインインしてコメントする。

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'

サインインしてコメントする。

### カテゴリ

Find more on Pulsed Waveforms in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by