Generating and plotting functions.

조회 수: 3 (최근 30일)
mar gal
mar gal 2020년 12월 26일
답변: Image Analyst 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
mar gal
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
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)

Image Analyst
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'

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by